0 votes

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
    get_node(commander).call_deferred(qFunction)
    queue_free()
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)
    queue_free()

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?

in Engine by (440 points)

2 Answers

+2 votes
Best answer

There's callv but no callv_deffered, 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)
queue_free()
by (4,081 points)
selected by

Fantastic, thanks much!

0 votes

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)

by (14 points)
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 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 webmaster@godotengine.org with your username.