Can I fix scripts in the saved file by migration?
- puzzletory
- Manual Inserter
- Posts: 3
- Joined: Fri Jun 05, 2020 6:29 pm
- Contact:
Can I fix scripts in the saved file by migration?
I'm developing a mod that contains only one scenario. All my code is in this scenario directories in several Lua scripts. I notice that if I fixed some issues in the scripts, the fix is used for a new game only. If I load the game from save that was created before the fix, the game still uses old code. I found this old code in the save file. I tried re-saved the game to another file, but It did not help. It is not a blocker for me now, but If I find some critical defect, I do not know how to fix it for players who have an unfinished game in save files. My scenario can take a long time. If my question is not clear, I can prepare an example mod that demonstrates this problem.
Re: Can I fix scripts in the saved file by migration?
As far as I understand your post, the piece of knowledge you are missing is, that if a scenario game is saved, all the scripts are saved with it. The savegame is independent from the scenario in the scenarios folder the game was started with.
So if you want to change the scenario scripts affecting your current game, just unpack the savegame - you will find all your scripts there, this game was started with. If you modfiy these script files, those modfications will only affect the specific game of that savegame. You can load the savegame after changing the scripts and they will immediately take effect in your game. It doesn't even need a factorio restart. Another savegame made after you loaded the first savegame with the modified scripts will contain those modified scripts. And so on.
The script files in the scenario folder being independent from the script files in each consecutive savegame also means, that you have to copy your updated scripts to the scenario folder, if you also want them to take effect in newly started games of that scenario.
In other words: Each savegame is its own scenario, because it has no outside script dependencies. Modfications to a savegame's scripts will immediately take effect when loading it.
In other other words: A scenario in the scenarios folder is nothing more than a savegame with a picture and an explanatory text slapped onto it.
So if you want to change the scenario scripts affecting your current game, just unpack the savegame - you will find all your scripts there, this game was started with. If you modfiy these script files, those modfications will only affect the specific game of that savegame. You can load the savegame after changing the scripts and they will immediately take effect in your game. It doesn't even need a factorio restart. Another savegame made after you loaded the first savegame with the modified scripts will contain those modified scripts. And so on.
The script files in the scenario folder being independent from the script files in each consecutive savegame also means, that you have to copy your updated scripts to the scenario folder, if you also want them to take effect in newly started games of that scenario.
In other words: Each savegame is its own scenario, because it has no outside script dependencies. Modfications to a savegame's scripts will immediately take effect when loading it.
In other other words: A scenario in the scenarios folder is nothing more than a savegame with a picture and an explanatory text slapped onto it.
Re: Can I fix scripts in the saved file by migration?
It should be possible the same way as we did for 0.18.28 when we needed to update PvP and other scenario scripts due to style changes and script changes - simply provide migration in your mod that has "game.reload_script()" in it. As long player has your mod enabled and updated, scripts should get replaced during load. Look at data/base/migrations/2020-05-27_Factorio_0.18.28.lua from Factorio.
- puzzletory
- Manual Inserter
- Posts: 3
- Joined: Fri Jun 05, 2020 6:29 pm
- Contact:
Re: Can I fix scripts in the saved file by migration?
Thank you for both replies! I added a migration script with game.reload_script() to my mod, and now it works.