Page 1 of 1

How to play the command after a certain time?

Posted: Fri Sep 08, 2017 8:02 pm
by WIZ4
What should I prescribe in the scenario, that every 10 minutes this command would be played
For example:

Code: Select all

player.print("Hello, world!")

Re: How to play the command after a certain time?

Posted: Fri Sep 08, 2017 9:27 pm
by Klonan
WIZ4 wrote:What should I prescribe in the scenario, that every 10 minutes this command would be played
For example:

Code: Select all

player.print("Hello, world!")
Something like this:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
  local interval = 10 * 60 * 60 -- 60 ticks per second, 60 seconds per minute, 10 minutes
  if (event.tick % interval) == 0 then
    game.print("It has been 10 minutes my dudes")
  end
end)
Documentation:
http://lua-api.factorio.com/latest/events.html#on_tick

Re: How to play the command after a certain time?

Posted: Sat Sep 09, 2017 12:18 pm
by WIZ4
Klonan wrote:
WIZ4 wrote:What should I prescribe in the scenario, that every 10 minutes this command would be played
For example:

Code: Select all

player.print("Hello, world!")
Something like this:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
  local interval = 10 * 60 * 60 -- 60 ticks per second, 60 seconds per minute, 10 minutes
  if (event.tick % interval) == 0 then
    game.print("It has been 10 minutes my dudes")
  end
end)
Documentation:
http://lua-api.factorio.com/latest/events.html#on_tick
Thanks for this, but how can I limit the number of repetitions?

Re: How to play the command after a certain time?

Posted: Sat Sep 09, 2017 1:07 pm
by prg

Code: Select all

if condition then script.on_event(defines.events.on_tick, nil) end