0 votes

Hi all,

I am making a tycoon game. I have a basic early part of my prototype up and am at the point where I'm about to start the real time aspect of the game.
In other words, all the pre conditions have been selected, added to lists etc and I'm ready to start the actual money making.

I've been reading a lot on the theory of tycoon games and there's a general feeling that they work on "ticks" to move through time. At each tick a whole range of functions are performed by each entity in the system.

What do you think is the best way to acheive this in Godot? Should I be running a _process(delta) and then on each pass through do my processing? How is a tick defined? I'm really interested in this so I can progress as best I can without having to re-write everything in a month as I chose the wrong way to advance.

Thanks a tonne...

in Projects by (810 points)

Tick is usually defined as an amount of time defined by who ever uses it(for example in minecraft the redstone works in ticks, where if you use a repeater you can define for how long it will hold - in ticks - it will hold the signal)... you can do so by making a timer of some sort, where every time it exceeds the time limit it will call a function/do all it needs to do and will reset itself

1 Answer

+1 vote

As Rusty commented, a tick is a short, but abstract period of time. For turn-based games, you need not worry much about it. For example, as soon as the player has made his or her choices and ends his/her turn, the AI will make its moves as quickly as possible(except maybe some real-time animations) and then hand control back to the player for the next turn. An RTS game in contrast (like your Tycoon game), will rely on real-time passage for continuous moves to happen at a constant rate. It’s important to keep a real-time clock for 2 reasons:
1. Not all CPUs/OS run at the same speed, and
2. As more units come into play, it will take longer to perform the needed functions for all the entities.

It’s easy enough to use delta to do this. Here is a simple example using a 2 second timer. That is probably longer than you would choose in practice, but it will demonstrate better.

extends Node2D

var my_timer = 2 # set to 2 seconds

func _process(delta):
    my_timer -= delta # take the time passed and subtract from our timer
    if my_timer <= 0: # 2 seconds have gone by... do stuff
        print ("Tick") # just to see that it prints every 2 seconds
        my_timer = 2  # reset timer for next time

func _ready():
    set_process(true)
by (308 points)

Great description, Michael.

Note that you can use the built-in Timer node for this as well.

func _ready():
    var timer = Timer.new()
    add_child(timer)
    timer.set_wait_time(2)
    timer.connect("timeout", self, "_on_Timer_timeout")
    timer.start()

func _on_Timer_timeout():
    print("Tick")
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.
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 webmaster@godotengine.org with your username.

Categories