kubecz3k / FiniteStateMachine

FSM plugin for Godot
MIT License
116 stars 22 forks source link

FSM transitions seems not to have access to a singleton #15

Open salvob41 opened 6 years ago

salvob41 commented 6 years ago

After having instantiate a globa singleton http://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html

this seems not be accessed by the transitions node, saying: - Compile Error: Identifier not found: global while the States node can access them

kubecz3k commented 6 years ago

@salvob41 yes, sorry about that, singletons/autoloads cant be used in tool scripts directly (but they still can be used if you fetch them with get_node. It's Godot limitation. To workaround please do something like this inside the script: onready var global = get_node("/root/global");

salvob41 commented 6 years ago

but it's weird... How can I access it through the States node? Are they not tool scripts?

kubecz3k commented 6 years ago

As I said you cant do it directly but you can use get node. (each singleton is an ordinary node that resides as a child of /root

salvob41 commented 6 years ago

Yes, Thank you for your reply. My comment was trying to make another point though. I'll try to explain better: When I try to access the global singleton from a State Node, I can do it. From the transition node, I cannot.

kubecz3k commented 6 years ago

yes, States are not tool scripts, Transitions are tool scripts. You can recognize this by the first line in the script. Tool scripts are the scripts that can be used inside editor. Transitions need to be tools since they are holding connections between states and the plugin need to fetch this information to build state graph. Hope in the future it will be possible to better distinguish between 'part of the script that need to work inside editor' and 'part of the script that need to work in runtime'. For now it's not possible and that's why there are couple limitations. (from anoother sideefect of transitions beeing a tool - if there will be syntax error inside transition, the editor will be unable to compile the script and fetch needed information, so the connection will dissapear from the graph)