Page 1 of 1

Question about recipe reset

Posted: Wed Mar 02, 2016 6:46 pm
by Nasabot
Hello, I have another question with lua.

As some people might know there is a command you can use ingame to update modded recipe cost
/c game.player.force.reset_recipes()
My wish is to implement this code in the "command"-lua file so this command is done everytime the game starts(initializes)
With
script.on_init(init)
it can be done, but the problem is, that this wont work as exspected.

Imagine this:

-Original Laser turret recipe cost is 5 batteries
-Mod changes it to 8
If you start game manually and use "/c game.player.force.reset_recipes()" it works as expected->turret costs 8 batteries

If the savegame already has the recipes updated(8 batteries) and you add /c game.player.force.reset_recipes() in lua-command file and restart the game the cost is then resetted 5 batteries

The weird thing is, that other recipes dont get resetted to its original state. I will try around a little bit, also this problem is not too important but if anybody knows how to fix this, it would be nice.
bascially what I want to do is to automate "/c game.player.force.reset_recipes()" so if I update my mod and other people download it, they dont miss this "mandatory" input.

Re: Question about recipe reset

Posted: Wed Mar 02, 2016 6:50 pm
by Supercheese
Instead of script.on_init, you should update the recipies in script.on_configuration_changed.

Re: Question about recipe reset

Posted: Wed Mar 02, 2016 9:50 pm
by Rseding91
Supercheese wrote:Instead of script.on_init, you should update the recipies in script.on_configuration_changed.
In addition to this, migration scripts are meant for exactly this: you change something that needs to be dealt with on any game the mod is loaded into.

An example: https://github.com/Rseding91/Landfill/b ... /2.1.3.lua

In versions previous to Landfill 2.1.3 the water-be-gone recipe took only wood. I updated it to take a single electronic circuit in 2.1.3 so I added that migration file which the game applies (and only applies once) to any game loaded with the mod.