Search code examples
godotgdscript

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'


Solution

  • 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());