I have been building TD nodes with python utility functions within them. For example, an animation might have a ‘back_to_start’ function. Unfortunately, when I call those functions from another node, they are run as if they are within the calling node, and so fail to find any relative operators. Is there a way to run a function as if it was being called from where its script is written.
Example:
def play_animation():
op("anim").play()
If I call this from a totally different part of my project, it won’t find op(“anim”). I’d like to be able to name the scope that I’m calling it from.
What I’ve been doing is making buttons that run my utility scripts and then calling their click functions from outside. This is clearly hacky and won’t work in the long run.
Just so we are clear, do you want op() to be relative to the node that contains play_animation(), or the one that is calling it?
The former should be the current behavior, if it’s not what you are experiencing please post a bug example.
If you want it to be relative to the calling node, then you should pass that node into the function via a parameter:
play_animation(callingNode):
callingNode.op("anim").play()
My issue is indeed that it is not behaving as you say should be the current behavior.
There’s a very simple example in the attached toe.
scope_bug.2.toe (5.15 KB)
I’m not crazy right? Can anyone verify the problem in my example?
Can you try upgrading to 5840 and see if it fixes it for you? I’m using an even newer build and it seems to work for me. If 5840 doesn’t work then you should expect this to work in the next release.
Yup. That new version worked