#functions in resources
1 messages · Page 1 of 1 (latest)
node.choice_one()```
there's a method specifically for this, get_tree().call_group("group", "choice_one")
choice one is a function in a resource script
which is not part of the scene tree so can't use get_tree()
So it is. phooey.
You could add a _ready() function that connects a signal that you emit instead of calling the function to the function itself.
That raises the question of how you get a reference to the signal in question. You could make it part of an autoload, for instance. There's also an interesting-looking solution found at this StackOverflow thread.
This requires an understanding of the "static" keyword, which allows a var to be accessed through the type itself rather than an instance of the variable. This is of course exactly the same as the autoload approach, but it's symbolically tied to the custom class you've created, which just feels better to me personally.
(example of static vs. non-static would be Color.BLACK accessing a const inside of the script for the Color type, whereas var instance:Color; instance.a accesses the a-component of an existing Color-type variable.)