Factorissimo - Seablock

by Saienai

Slight modifications to make a better factorissimo - seablock experience. Meant to be played as the provided scenario, not standalone

Mod packs
1 year, 8 months ago
1.1
1.12K

g Misunderstanding of how Factorio works

Honktown β˜†
1 year, 8 months ago
(updated 1 year, 8 months ago)

Unfortunately, and please don't take this as an insult, there is a gross misunderstanding of Factorio's modding/Lua Environment.

In simple terms, there are no persistent variables in the global scope, they're lost when the game is saved/loaded (and are defined only when the scenario/control file is ran - which it is, every game load)

A quick patch to make this work, without setting it up the "right" way:

Instead of mainSurface =, it should be written, e.g.:
local function spawnFish()
local mainSurface = game.surfaces.nauvis

...
local function spawnGarden()
local mainSurface = game.surfaces.nauvis

```
local function spawnTree()
local mainSurface = game.surfaces.nauvis

The original code only defines the variable mainSurface when spawnFish executes. If spawnFish was not the first function executed after save/load, one will get mainSurface is nil errors.

The longer, better way is during on_init, assign that surface you want to global (the special table that's saved and loaded scenario/mod control), as something like global.mainSurface. Then it will always be present across save/load.

I can offer some help in Factorio's #mod-making discord, because when you borrow Freeplay, you also borrowed the vanilla event handler, which is more complicated than it needs to be (I can give you a very simple event handler file - otherwise Factorio will overwrite other script.on_<init/reconfig>, or script.on_event(identity, function-to-call) lines, and not do what is desired)

Honktown β˜†
1 year, 8 months ago

P.s. to fix existing games people are playing will require a bit more work, as scenarios are not generally meant to be updated (scenario files are written in the save and do not automatically get replaced/updated).

1 year, 8 months ago

well, that was stupid of me - I originally had it all in a single function call but decided to split it into 3 in order to give them different update times (ex: fish spawn faster).
I will publish an update, but as you said there isnt much to be done about the currently created scenarios as you would need to edit the control file in the specific save game.

Honktown β˜†
1 year, 8 months ago
(updated 1 year, 8 months ago)

I will publish an update, but as you said there isnt much to be done about the currently created scenarios as you would need to edit the control file in the specific save game.

It can be handled with a migration in the mod. If someone ran the scenario from the scenarios (Mod scenarios) a migration in your mod can cause the game to reload the scenario files. For anyone who put the scenario in their scenarios folder, they will have to edit that and do /c game.reload_script(), or edit their save. If you gave me collab permissions for a day or two (Permission tab-> Invite) I can do what's needed, or contact me on Discord/the forum

Edit: (I'm sure anyone who's game is error'ing wouldn't mind getting a fix <_< )

1 year, 8 months ago

Sure, I dont mind.

Honktown β˜†
1 year, 8 months ago
(updated 1 year, 8 months ago)

Alright, uploaded a new version. "Unfortunately" did a bunch of style changes and patched the changelog, too. For sanity reasons.

New response