How to play the command after a certain time?

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

How to play the command after a certain time?

Post 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!")
My native language is russian. Sorry if my messages are difficult to read.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post 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

User avatar
WIZ4
Fast Inserter
Fast Inserter
Posts: 209
Joined: Thu Apr 07, 2016 1:36 pm
Contact:

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

Post 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?
My native language is russian. Sorry if my messages are difficult to read.

User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

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

Post by prg »

Code: Select all

if condition then script.on_event(defines.events.on_tick, nil) end
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Post Reply

Return to “Gameplay Help”