Script command to automatically update existing constructions when savegame is loaded?

Willkommen in der Transport Fever Community

Wir begrüßen euch in der Fan-Community zu den Spielen Transport Fever und Train Fever, den Wirtschaftssimulatoren von Urban Games. Die Community steht euch kostenlos zur Verfügung damit ihr euch über das Spiel austauschen und informieren könnt. Wir pflegen hier einen freundlichen und sachlichen Umgang untereinander und unser Team steht euch in allen Fragen gerne beiseite.

 

Die Registrierung und Nutzung ist selbstverständlich kostenlos.

 

Wir wünschen euch viel Spaß und hoffen auf rege Beteiligung.

Das Team der Transport-Fever Community


  • Hi all, I'm looking for a script command to put in my mod that will automatically update any existing constructions (modular rail stations) on the map of a savegame when it is loaded. So far I have not found a solution from the API reference and studying other mods (also I'm still new to TpF scripting!).


    Context: I have an existing mod that used the postRunFn to change the updateFn of rail tracks to a custom script fileName. I did not use a wrapper function in that case, therefore the mod overrides any existing updateFn (badddd I know!). I have since learned a much better way to do things so that custom script file is no longer needed.


    The problem is that existing savegames already have rail stations on the map built with that early version of the mod. As you know, a station does not update to the latest mod code until it is manually "tickled" by the user with Configure and add/remove a module. Before the user does that, the updateFn of the modules in the station still point to the old custom script file. So if the user tries to toggle a construction param setting available in the updated mod while that custom script file is no longer on disc, there is an instant crash to desktop. The error is base_config.lua ConstructWithModules "tab" value is empty -- because it's looking for the old custom script file that was assigned to the module when the station was built, but which is no longer on disc.


    If instead the user manually adjusts the station first, all the modules update so they no longer point to the old custom script file for updateFn. Now the user can toggle the new param option in the mod and nothing crashes.


    So one option seems to be to simply leave the old custom script file in the mod package as a "legacy reference" to prevent crashes. It will never be run again by the mod, it's just an unused file. It exists only to prevent a CTD with any existing stations before the user manually Configures them.


    But is there a "cleaner" way to do this? A method that automatically forces an update of existing constructions on the map when the savegame is loaded, so that the modules use the current updateFn definition and not the previous custom script? And that will let me remove that custom script file from the mod package?


    I am currently looking at something called "game.interface.upgradeConstruction" and not finding any documentation how to use it.


    Many thanks!


    PS in base_config.lua if I add a print(params) command for debugging, all of the modules in the station show "" for the updateFnScript fileName. So it's like part of base_config.lua has the updated mod definition, but somewhere it is still trying to find the old script file.

    Einmal editiert, zuletzt von RadiKyle ()