I want to have a world time happening/counting as the game progresses. What's the best way to do this?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

Starting a new game. This game will want time to tick on by.
Y1 W52 D28

I want the game to have two speed settings and the ability to pause as I enter menus etc.

Should I use a timer for this?
The thing is I want to start at 0 and count UP I’m guessing.

Does anyone have any suggestions on the best way to tackle this?

Thanks so much…

:bust_in_silhouette: Reply From: YeOldeDM

You can easily increment a timer variable in a _process(delta) function. Adding delta to a value will cause that value to increase by 1 per second. You can multiply this by a value to get different “speeds” and prevent time from increasing with an if check to pause time.

var time = 0
var time_mult = 1.0
var paused = false

func _ready():
  set_process(true)

func _process(delta):
  if not paused:
    time += delta * time_mult

So simple and elegant. Thanks a tonne… Much appreciated.

Robster | 2017-08-16 03:34