This is a good shout now that you mention it! I think I made the Global script the one thats on the root, so it wasnt able to find any children.
I’ll mark this as the solution if I can find my way out of this, many thanks for your help!
You seem to be not fully understanding how autoloads/globals work.
Strictly speaking there’s no such thing as “global script” in Godot. Setting a script as a global autoload won’t turn normally attached script into a global script. It doesn’t work like that.
What happens when you set a script to be a global autoload - At startup Godot will instantiate a “hidden” node with the script attached, parent it to root, and make that script accessible globally via name you chose, in your case ClickCords.
From then on it makes no sense to have this script attached to normal nodes in the scene. Because the script will now run two instances, causing bugs.
So when you say ClickCords.cords you’re accessing cords in /root/ClickCords not in /root/main/Map/LaneContainer. The former hasn’t got any children so it will never put anything into cords array. And that’s precisely what you’ve got - an empty array.
That definitely was a learning experience. It’s fixed now, thanks a lot!
How did you fix it?
I defined ClickCords with a variable to get_node(LaneContainer), instead of just adressing it through the global
Take care to disable that autoload, otherwise you may still have bugs in the future as you’re running the same script twice in parallel.
If you want to store the coords in a globally accessible array, make a fresh autoloaded script containing only that array. Then in click_cords.gd write to that array instead of local array, and read from it in the other script.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.