How to Invoke a Function from Another Node Script?

I'm trying to invoke a function from one node into another

Node1_script:

extends Position2D

func sample():
    print('well you invoked me, now what?')

Node2_script:

tool
...


func some_function():
    print($"Node1".sample());

but it gives the error:

Invalid call. Nonexistent function 'sample'

3

1 Answer

Ah I got the problem, it was in tool mode

for future reference, if you want to invoke a function in tool mode you have to make sure the function definition is also in tool mode:

Node1_script:

extends Position2D
tool

func sample():
    print('well you invoked me, now what?')
    

Node2_script:

tool
...


func some_function():
    print($"Node1".sample());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest