Explanation of "defines.events.on_tick" behavior
Posted: Wed Nov 27, 2024 5:30 pm
Hello,
I am currently trying to understand the trigger logic behind the "defines.events.on_tick" event. I have the following code implemented in control.lua:
Everything is as expected; I can see the game printing the message 4 times per second (on each tick, where the remainder of the the current tick divided by either 15, 30, 45, or 60 equals 0). No the puzzling part: I change the code of the update function to this:
Now the code gets called once per second; not (as I expect) 4 times per second. I can't wrap my head around why that is... can someone shed some light here?
Thanks!
I am currently trying to understand the trigger logic behind the "defines.events.on_tick" event. I have the following code implemented in control.lua:
Code: Select all
update_ticks = {15, 30, 45, 60}
script.on_event(defines.events.on_tick, function(event)
update(event)
end)
function update(event)
for i=1,#update_ticks,1 do
if event.tick % update_ticks[i] == 0 then
game.print("updated at tick ".. event.tick)
end
end
end
Code: Select all
function update(event)
for i=1,#update_ticks,1 do
if event.tick % update_ticks[i] == 0 then
game.print("updated at tick ") -- I simply removed the reference to event.tick here
end
end
end
Thanks!