This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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
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?

in Engine by (449 points)

3 Answers

+3 votes
Best answer

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)
by (4,246 points)
edited 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)
0 votes

If you need a callv_deferred, try:

func callv_deffered(callback:String, args:Array):
    call_deffered("callv", callback, args)
by (23 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 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.