0 votes

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
     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!

in Engine by (429 points)

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.

I forgot that timers exist. I always manage myself timed events with a variable and fixedprocess, since it costs almost nothing to execute for the CPU.

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...

@goku haha, i never forget than, i think they are so powerfull, when timer.is_active() be implemented, there will be a great improvement!

1 Answer

0 votes
Best answer

Timer.is_active() has been added to the development branch for godot. So if you want to make a custom build visit the git hub here. If you don't want to do this then, continue to use the method you have been. I personally have asked this question before and I feel that timers should have the option to reset when Timer.start() is called as well as the option to prevent this like you are wanting. You could request this as a feature if you still don't like Timer.is_active() at the git hub issues here.

by (246 points)
selected by

Times.is_active() looks just fine. Will wait for next release. Thanks for the info

Not a problem.

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.