Lua Help - Loop with waits, run per nth tick
Posted: Sun May 03, 2020 7:49 pm
Hello,
I am new to working with the factorio api and am trying to determine a way i can have code applied for X seconds to a target play determined by a chat integration.
the idea is to allow chat in a live stream be able to spawn things in over a duration or cause random attacks over an amount of time, the interface is using rcon and sends the command as 1 string.
I was looking at trying to use the game.tick value and while loops to get this behaviour although the busy wait tends to crash the game. I have been unable to figure out how to use the script events to run on tick in this situation allow me to code spawning in groups of tree's around the player every second for 10 seconds then quit. it appears the script on_nth_tick would work although i am unsure how to stop it after the specified time has elapsed.
Please help me out and i appreciate any idea's on how to implement a time based loop that terminates after X seconds
I am new to working with the factorio api and am trying to determine a way i can have code applied for X seconds to a target play determined by a chat integration.
the idea is to allow chat in a live stream be able to spawn things in over a duration or cause random attacks over an amount of time, the interface is using rcon and sends the command as 1 string.
I was looking at trying to use the game.tick value and while loops to get this behaviour although the busy wait tends to crash the game. I have been unable to figure out how to use the script events to run on tick in this situation allow me to code spawning in groups of tree's around the player every second for 10 seconds then quit. it appears the script on_nth_tick would work although i am unsure how to stop it after the specified time has elapsed.
Please help me out and i appreciate any idea's on how to implement a time based loop that terminates after X seconds