0
Answered

Is there a way to set a variable for a state graph where every state defined inside can access it but other Bolt graphs on the object could not?

alex oatridge 4 years ago updated by Lazlo Bonin (Lead Developer) 4 years ago 4

I would like to assign a bool for mouse down and would love to check that bool from different states in a graph. I would want that bool to be private in that scope so no other graph on the game object can modify. Any ideas on how to pull that off the Bolt way.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Well that is something brought up a few times. Not possible in a simple way. You would need to have setter and getter events. on both sides. Take a look at my wait loops macros, I do it in there, link below. There are some things coming in the roadmap I'm sure will help. Like custom event definitions.

https://support.ludiq.io/forums/5-bolt/topics/570-delayed-execution-collection/

Otherwise, there are certain ways something native could be made eventually with the API, but nothing yet. Though I'm working on encapsulation stuff, it's a ways off. Won't be too long till I am ready for early testing though.

Here is the specific part. You can also do a naming scheme, by adding an int id like i did based on GetHash or something. Since it's always different.If you need instance variables beyond a specific one.


Essentially, you have a getter on the object you need to get from. And a setter on the object receiving the variable. The getter is there just to know the variable is being gotten. Then you use that event and fire the event to set it on the other object, or other unit. That is why an instance ID is important, if it is on the same object. Each variable to get, only needs to set it once with an id.


+1

Thanks for the info. Just wanted to ask before I made a ton of variables then find out a few months later I was doing it wrong.

Answered

Variable accessibility modifiers (private / protected / etc.) is one of the language items I decided not to include in Bolt to simplify things. In this case, just use an object variable, and make sure you don't modify it from elsewhere.

I'll be closing this in favor of this thread: Machine scope for variables

https://support.ludiq.io/forums/5-bolt/topics/400-machine-scope-for-variables/