Transport Fever 2

Transport Fever 2

Create your own game world!
Give your game a personal touch and change it to your liking. Create, share and install mods. Customize the game with new landscapes, vehicles, stations, assets and more.
RadiKyle 6 19 Jun, 2024 @ 6:54am
Force stations to update after mod update?
Hey all, if I update a mod related to modular stations (or any other type of construction), is there a way to force existing stations in a savegame to automatically update to the new version when loaded?

For some reason the game does not do this. Currently I have to tickle each station by making a temporary change to it in the Configure menu. I'm looking for an API script command to update it automatically.

Thanks!
< >
Showing 1-9 of 9 comments
lollus 15 20 Jun, 2024 @ 5:44am 
Theoretically, you could try a script that fires on game start and calls game.updateConstruction() (the new api has no such thing so you need the old one), but I wouldn't bother.
RadiKyle 6 20 Jun, 2024 @ 8:10am 
Thanks lollus. I wonder why they removed it from the API?

Maybe it's a good thing... If a mod update is something that crashes (because mod conflict or whatever), and the game automatically updates everything at start, then it would insta-crash at every start. Maybe a little more difficult to find out what's wrong.

Still sucks having to manually update every single construction after every mod update tho... 😵
Last edited by RadiKyle; 20 Jun, 2024 @ 8:11am
RadiKyle 6 10 Oct, 2024 @ 8:04pm 
Hey all, returning to this as I'm once again looking for an automated way to update constructions after a mod change.

I'm using a loadConstruction addModifier to add a new user-selectable option to modular rail stations (vanilla plus a few specified mods).

When I load the game, if I modify an existing station first to "refresh" it (add/remove a component) and then toggle the new option, it works okay, though I have to toggle the option off then on again to see the effect.

BUT if I load the game and toggle the new option without first refreshing the station, it's instant CTD 💥 Since doing that is completely natural this is unusable because there'll be so many crashes.

How can I refresh all existing stations when the game loads so that this crash doesn't happen when the new option is toggled for the first time?

I tried running the base_config.lua function game.config.ConstructWithModules(params) inside the postRunFn of mod.lua but it also crashes due to missing data.

Thanks
lollus 15 13 Oct, 2024 @ 4:46pm 
You could try a game_script that only fires at game start, eg load(loadedState) only fires once in the worker thread and many times in the GUI thread. If it has no access to GUI resources, then you are in the worker thread and it will only fire once.
Then you can try game.interface.upgradeConstruction(), copy from the freestyle station itself.
I really think you should not do this though.
RadiKyle 6 13 Oct, 2024 @ 5:05pm 
Yeah you're probably right... I was thinking afterward what happens if my automatic change creates an unstable element that crashes, it could brick the savegame.

Anyhow I skipped it. The context was a mod used to have a .script file that is no longer needed so I removed it. But before the stations are updated by the user, the modules still point to that file so it crashed. I restored the file and the crashes stopped. It's unused so it's just there for legacy support now.

I tried using an addModifier to change the script reference but it still crashed. The reference in stored savegames seems to be at a lower data level than the tables that we access via lua/API commands.

I forget if I also tried it in postRunFn too...

I looked at the "station / industry bulk upgrade" mod and it uses some API functions to update things, but it's in response to a user selection in the GUI.
Last edited by RadiKyle; 13 Oct, 2024 @ 5:06pm
lollus 15 14 Oct, 2024 @ 9:34am 
The modifiers run in different lua states, so they have access to different data. They are like separate threads. You can use modifiers to overload updateFn() (not to fire it), so when it runs (in its usual lua state and under the usual conditions) it does something extra. Some mods do that.
However, you want to 1. fire 2. upgradeFn() here, which is something else.
RadiKyle 6 14 Oct, 2024 @ 10:17am 
I think the issue is how the data from the savegame gets handled. Here's the situation...

- Old mod set the updateScript.fileName of station modules to a custom .script file.
- Build stations with old mod and save game.
- New mod v2 doesn't set updateScript.fileName anymore because that script is not used now. New mod also adds a new construction.param option for the user.
- Load savegame, and user toggles the new param option on an existing station, instant CTD. Error indicates the game (specifically base_config.constructWithModules) is still trying to find the old .script file from v1.

- Load savegame, add/delete a module to update existing station first, no crash. Then toggle the new param option, no crash.

So it's the combination of the removal of an old .script file, and toggling a new param option that didn't exist before.

It seems that when that first update occurs, an existing station is still using stale data that was in the savegame, not the current mod definition. And for some reason the new param option seems to be involved. I mean I can remove the old .script and nothing crashes. But if I add a new param option and toggle that first, then it crashes and says it can't find the old .script 🤷‍♂️
N0neGiv3N 11 8 Nov, 2024 @ 3:51pm 
All you have to do is:

* Delete the station.

* Undo the deletion via Undo Mod.

When it reappears it will be the same configuration you had it in track/platform wise, but it will be the updated version scripting wise.

If that is not what you wanted, then I may have misunderstood your question.
Last edited by N0neGiv3N; 8 Nov, 2024 @ 3:52pm
RadiKyle 6 8 Nov, 2024 @ 5:23pm 
I was looking for a script method to do it automatically as part of a mod, so no user action required. But it's messy and there's a possibility of bricking everybody's savegames if something goes wrong so I've given up on it (for now, hehe... )
< >
Showing 1-9 of 9 comments
Per page: 1530 50