Page 1 of 1

run a command every X

Posted: Sat May 28, 2016 11:36 am
by NosajDraw
Is there a way to run a command (console command) every minute (or other frequency)?

Re: run a command every X

Posted: Sat May 28, 2016 12:37 pm
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)

Re: run a command every X

Posted: Sat May 28, 2016 3:22 pm
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.

Re: run a command every X

Posted: Sat May 28, 2016 3:48 pm
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

Re: run a command every X

Posted: Sat May 28, 2016 11:03 pm
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.

Re: run a command every X

Posted: Sat May 28, 2016 11:04 pm
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.

Re: run a command every X

Posted: Sat May 28, 2016 11:23 pm
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)

Re: run a command every X

Posted: Sat May 28, 2016 11:27 pm
by DaveMcW
Alt+M opens a special big map with pollution disabled. Press Alt+M again to close it. ;)

Re: run a command every X

Posted: Sat May 28, 2016 11:30 pm
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.

Re: run a command every X

Posted: Sat May 28, 2016 11:31 pm
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.

Re: run a command every X

Posted: Thu Feb 03, 2022 3:09 am
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.

Re: run a command every X

Posted: Thu Feb 03, 2022 3:51 am
by robot256
Is this a good use for on_nth_tick?

Re: run a command every X

Posted: Thu Feb 03, 2022 4:56 pm
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