Is there a way to translate an array's contents to arguments for a call()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By denxi

I’m trying to make a system to set functions with a frame delay, then execute them when the delay is up. The system works right now for delaying functions that have no arguments, however as it is right now it doesn’t work on functions with arguments, as the argument count depends on the function. I think I have a way to make it work using arrays, but I’m not sure how, if I can, transfer the contents of an array to a call_deferred as actual functions. Is there any way to do this? Right now it looks like

if args.size() == 0:
    #If there are no elements in the args array, run the function normally
elif args.size() > 0:
    #If there are elements in the args array, run the function using the elements as args
	get_node(commander).call_deferred(qFunction, args)

Obviously the problem with this is that it’ll try to run the qFunction with the args array as an argument. I’m looking for a way to have it run the qFunction, but using each array element as an argument. Is there any way to do that?

:bust_in_silhouette: Reply From: Dlean Jeans

There’s callv but no callv_deferred, so I guess you can do this:

# you don't need to check for args.size()
# 'cause it's fine to pass with empty array []

yield(get_tree(), 'idle_frame')
get_node(commander).callv(qFunction, args)

Fantastic, thanks much!

denxi | 2019-02-25 15:40

:bust_in_silhouette: Reply From: Perodactyl

A better version of @Dlean Jeans code:

func callv_deffered(callback:String, args:Array):
    call_deffered("callv_deffered_finish", [args,callback]
func callv_deffered_finish(args:Array, callback:String):
    callv(callback, args)
:bust_in_silhouette: Reply From: teknixstuff

If you need a callv_deferred, try:

func callv_deffered(callback:String, args:Array):
	call_deffered("callv", callback, args)