on_tick_20 & on_tick_60 events

Things that already exist in the current mod API
Post Reply
UberWaffe
Fast Inserter
Fast Inserter
Posts: 202
Joined: Mon May 04, 2015 4:53 am
Contact:

on_tick_20 & on_tick_60 events

Post 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;

Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: on_tick_20 & on_tick_60 events

Post 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.
Last edited by Rahjital on Sat Jul 25, 2015 9:57 pm, edited 1 time in total.

UberWaffe
Fast Inserter
Fast Inserter
Posts: 202
Joined: Mon May 04, 2015 4:53 am
Contact:

Re: on_tick_20 & on_tick_60 events

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

Post Reply

Return to “Already exists”