+1 vote

I need to call the function call(function_name, arg1, arg2...), but all the arguments are in one array of varible length. (the function in which i'm calling call() of a different node might end up getting arguments like this: function_name = fn1, args = [argument], or like this: function_name = fn2, args = [position, velocity, UP].

The call() function appears to only allow passing the args one by one, not in an array.

How do I deal with this?

Godot version 3.4.4
in Engine by (92 points)

1 Answer

+1 vote
Best answer

Well I know of two possible ways to deal with this, you can pass a dictionary to a function as an argument like this

func Example(Dict={}):

and you can then pass the function example a dictionary which you can unpack within the function. Alternatively you can use an autoload script as a way of passing information around. If you have an array variable in an autoload script you can add items and read items too it from any other script in an active scene.

by (2,001 points)
selected by

thanks, i've thought about this, the dictionary method limits the functions i can call just to those built specifically for being called by this, but that's fine i guess. The autoload is too difficult for me to understand, but thanks for helping!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.