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?

asked Feb 25, 2019 in Engine by denxi (403 points)

1 Answer

+1 vote
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()
answered Feb 25, 2019 by Dlean Jeans (3,864 points)
selected Feb 25, 2019 by denxi

Fantastic, thanks much!

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.