Page 1 of 1

on_tick_20 & on_tick_60 events

Posted: Fri Jul 24, 2015 3:28 pm
by UberWaffe
Request: A tick event that only fires every 20 ticks (3 events per second.), and another that only fires every 60 ticks (One event per second). Events should have the same event.tick available as the normal tick event.
Purpose: Less performance hungry tick options for entities/code that do not require fast update cycles.
Can currently be achieved by using if statements and checking the number of ticks passed since last execution, but can still end up being thousands of unneeded if checks if large lists are involved.

Examples: Simulating tree growth; Weather patterns; Simulating alien strategic decisions;

Re: on_tick_20 & on_tick_60 events

Posted: Fri Jul 24, 2015 5:02 pm
by Rahjital
Why not just use modulo? Like:

Code: Select all

if event.tick % 20 == 0 then
    whatever code you need to be run every 20 ticks
end
You only ever need one if statement for that.

Re: on_tick_20 & on_tick_60 events

Posted: Fri Jul 24, 2015 6:24 pm
by UberWaffe
You are entirely correct.
For some reason I had it in my head that it would get called per entity, not per registered game.on_event(.

Forget I suggested anything.