Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | tiernich | |
Old Version | Published before Godot 3 was released. |
I’m using a lot of Timers
in a current project. My approach is:
TimerState = false
func fixed_process( delta ):
if TimerState == false:
get_node( "/timer" ).start()
TimerState = true
#do stuff
...
On_TimerOut():
TimerState = false
I do that because the Timer
is in fixed_process
, every time this function is executed, timer
is restarted withou even finish. Assuming that i must have this timer
in fixed process
, there is a way to check if the Timer
is runnig, to not restart? Something like if timer.is_runnig() == true
?
Or i am using timer wrong
Or the only way is having a variable to check has i did above?
Thanks folks!
Why do you need to have the timer in _fixed_process
though? Typically you could just have the timer restart itself in its timeout callback, instead of checking at each frame if it’s running and restarting it when it’s not.
Akien | 2016-04-22 07:40
I forgot that timers exist. I always manage myself timed events with a variable and _fixed_process
, since it costs almost nothing to execute for the CPU.
Gokudomatic2 | 2016-04-22 08:46
I’m developing an AI, and need check many states every frame, and this states are functions like shoot, and i have timers for reloading, firerate, even turn around take some time, the timers are in thoose functions in fixed process, because they need be executed every frame… well, maybe there is a better approach to this. Is my first serious AI and i am learning, maybe i will change the process in the future…
tiernich | 2016-04-22 15:21
@goku haha, i never forget than, i think they are so powerfull, when timer.is_active() be implemented, there will be a great improvement!
tiernich | 2016-04-22 15:23