Simple Timer (Not a question)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Squabix

If you are new to timers, here’s a simple timer that you can create:

count = 0

func _process(delta):
    if count == 60:
        print("Waited one second")
        count = 0
    else:
        count += 1

The code above creates a one second timer because the _process function is called every frame (60 times a second). If count is not 60 yet, 1 gets added to count. If count is 60 (one second has passed), it executes what happens every second, and count goes back to 0. I hope this helps!

:bust_in_silhouette: Reply From: Dlean Jeans

Why not use the Timer node?
FPS could be unstable so I think your script may not get you exactly 1 second.

That’s true, so you shouldn’t use this for bigger games. The main reason to use this is if you had to write code inside the timer (Like I’m having to in a game I’m making). Thanks for your reply.

Squabix | 2019-06-20 12:16

What you mean by “write code inside the timer”? You can access its properties from anywhere.

Dlean Jeans | 2019-06-20 12:51

Okay, you stumped me :slight_smile:

Squabix | 2019-06-20 13:29