Invoking a Lua command on startup?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
wrsomsky
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jun 19, 2017 10:02 pm
Contact:

Invoking a Lua command on startup?

Post by wrsomsky »

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?

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Invoking a Lua command on startup?

Post by bobingabout »

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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1190
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Invoking a Lua command on startup?

Post by Mooncat »

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. ;)

wrsomsky
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jun 19, 2017 10:02 pm
Contact:

Re: Invoking a Lua command on startup?

Post by wrsomsky »

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.

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

Re: Invoking a Lua command on startup?

Post by prg »

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!

wrsomsky
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jun 19, 2017 10:02 pm
Contact:

Re: Invoking a Lua command on startup?

Post by wrsomsky »

Hmm... Killing the process is a bit heavy-handed, but should be workable, assuming the killed Factorio doesn't leave "droppings" about...

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

Re: Invoking a Lua command on startup?

Post by prg »

Code: Select all

  17.687 Received SIGTERM, shutting down
  17.789 Goodbye
It'll still shutdown cleanly if you give it the chance, i.e. use SIGTERM or SIGINT instead of SIGKILL.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!

Post Reply

Return to “Modding discussion”