Invoking a Lua command on startup?
Invoking a Lua command on startup?
I'm looking to put together a tool to make a large scale segmented "screenshot" directly from one or more save files, batch-style. I've seen the mods/scripts that will generate such things, but the conventional way to invoke them is to be playing the game and then enter a command / push a button / etc. What I'm thinking of is a batch script that would start factorio w/ some command-line option (?) telling it to load the game as usual, get everyting loaded and ready to go, but just before starting the "game-play" loop to execute some command which would invoke the script to take the screenshot and then exit the game. Is there such an option available? Have I missed something? Any info on how to do this?
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Invoking a Lua command on startup?
I think the closest you can come to your request in the game as it is right now is to use an on_init event. As soon as the game is initialised, it will run that script.
I'm fairly sure that will run if you load a game the first time a mod is loaded too.
The problem is, it will just do this initialisation flash once, then the game will continue as normal. no exit, and no command line.
This is why you usually have buttons and the like to do this thing, so that it's not just a 1 off flash bang event.
I'm fairly sure that will run if you load a game the first time a mod is loaded too.
The problem is, it will just do this initialisation flash once, then the game will continue as normal. no exit, and no command line.
This is why you usually have buttons and the like to do this thing, so that it's not just a 1 off flash bang event.
Re: Invoking a Lua command on startup?
on_init is called only once for each save, so it is not repeatable. You may also want to use on_load.
But I think taking screenshot in on_init or on_load does not work, since the screen is not ready. Haven't tested though.
In case it doesn't work, you may need to use the on_tick event. Here is a not-for-multiplayer solution:
1) create a local boolean variable
2) in on_init and on_load, set its value to true
3) in on_tick, if its value is true, set it to false and take screenshot
I used a similar trick to show the initial popup in Creative Mode.
But I think taking screenshot in on_init or on_load does not work, since the screen is not ready. Haven't tested though.
In case it doesn't work, you may need to use the on_tick event. Here is a not-for-multiplayer solution:
1) create a local boolean variable
2) in on_init and on_load, set its value to true
3) in on_tick, if its value is true, set it to false and take screenshot
I used a similar trick to show the initial popup in Creative Mode.
Re: Invoking a Lua command on startup?
I was able to use on_tick to do a screenshot on startup. But what would be nice now, is a way to *end* the game at that point and either load the next save to be "screenshotted" or exit factorio completely to let a new instance be started for the next save.
Re: Invoking a Lua command on startup?
print("screenshot done"), listen for that string with a script, kill the process.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Re: Invoking a Lua command on startup?
Hmm... Killing the process is a bit heavy-handed, but should be workable, assuming the killed Factorio doesn't leave "droppings" about...
Re: Invoking a Lua command on startup?
Code: Select all
17.687 Received SIGTERM, shutting down
17.789 Goodbye
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!