run a command every X

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

run a command every X

Post by NosajDraw »

Is there a way to run a command (console command) every minute (or other frequency)?
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5266
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: run a command every X

Post by Klonan »

Something like this:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
	if event.tick % 60*5 == 0 then --every 5 seconds 
		some_function(event)
	end
end)
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

Re: run a command every X

Post by NosajDraw »

Great thanks :)

I am 100% clear of pollution... actually its not the pollution I care about, its being able to see the map that I want, and now I can :)

Code: Select all

/c script.on_event(defines.events.on_tick, function(event)
   if event.tick % 60*60 == 0 then --every 60 seconds
	local surface = game.local_player.surface; for coord in surface.get_chunks() do surface.pollute({coord.x * 32, coord.y * 32}, -10000000) end
   end
end)
A little surprised the code works, was expecting it to get upset with the "local" variable definition inside a loop.

After I did this, it did occur to me that perhaps there was a way to stop pollution occurring which would be kinder on the old CPU cycles.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: run a command every X

Post by Choumiko »

NosajDraw wrote:I am 100% clear of pollution... actually its not the pollution I care about, its being able to see the map that I want, and now I can :)
Or you just press Alt when in map view? Unless i completely misunderstand what you are after. Removing pollution makes biters kind of pointless since they won't evolve/attack
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

Re: run a command every X

Post by NosajDraw »

Choumiko wrote:
NosajDraw wrote:I am 100% clear of pollution... actually its not the pollution I care about, its being able to see the map that I want, and now I can :)
Or you just press Alt when in map view? Unless i completely misunderstand what you are after. Removing pollution makes biters kind of pointless since they won't evolve/attack
I play on peaceful and I think it's a mod I have that totally removes the biters, the pollution is just an annoyance for me.

My interest in the game is making things do things, I really dislike the whole biters side of things, it certainly adds nothing to the game for me, quite the opposite.
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

Re: run a command every X

Post by NosajDraw »

Oh, and the timer code doesnt work, at least not long term, it seemed to work for a while, but now the pollution is back.
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

Re: run a command every X

Post by daniel34 »

NosajDraw wrote:Oh, and the timer code doesnt work, at least not long term, it seemed to work for a while, but now the pollution is back.
The command will stop working after you reload the save. If you want to have it permanently you'll need to include it as a mod or directly in the control.lua of the savegame.
NosajDraw wrote:I am 100% clear of pollution... actually its not the pollution I care about, its being able to see the map that I want, and now I can :)
If it's only the pollution on the minimap that's bothering you, just disable Options --> Graphics --> Show pollution on minimap when detailed info is on (doesn't work on the big map)
quick links: log file | graphical issues | wiki
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3714
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: run a command every X

Post by DaveMcW »

Alt+M opens a special big map with pollution disabled. Press Alt+M again to close it. ;)
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

Re: run a command every X

Post by NosajDraw »

daniel34 wrote:If it's only the pollution on the minimap that's bothering you, just disable Options --> Graphics --> Show pollution on minimap when detailed info is on (doesn't work on the big map)
Oh cool, thanks, yes for the most part its the pollution on the minimap that annoys me.
NosajDraw
Inserter
Inserter
Posts: 32
Joined: Mon May 12, 2014 11:36 am
Contact:

Re: run a command every X

Post by NosajDraw »

DaveMcW wrote:Alt+M opens a special big map with pollution disabled. Press Alt+M again to close it. ;)
OK, will take a look at that when I reload.
Annihilannic
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Feb 28, 2021 10:13 pm
Contact:

Re: run a command every X

Post by Annihilannic »

Klonan wrote: Sat May 28, 2016 12:37 pm Something like this:

Code: Select all

script.on_event(defines.events.on_tick, function(event)
	if event.tick % 60*5 == 0 then --every 5 seconds 
		some_function(event)
	end
end)
Actually

Code: Select all

% (60*5)
due to operator precedence.
robot256
Filter Inserter
Filter Inserter
Posts: 875
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: run a command every X

Post by robot256 »

Is this a good use for on_nth_tick?
jagholin
Inserter
Inserter
Posts: 32
Joined: Mon Jan 06, 2020 7:19 pm
Contact:

Re: run a command every X

Post by jagholin »

robot256 wrote: Thu Feb 03, 2022 3:51 am Is this a good use for on_nth_tick?
i guess, this is a thread from 2016

right now there are ways to solve OPs problem without console commands:
map view has filters that can be toggled on/off(to not display pollution).
map gen settings can be changed to disable pollution on the map with /editor, mapgen settings mod or with a command
Post Reply

Return to “Gameplay Help”