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 8 Jun, 2024 @ 9:08am
Add fields/subtables to a Module resource with postRunFn?
Hey all, I'm bumping into a barrier and just want to confirm if it's real and if there is a work-around.

I want to use postRunFn to add a new field (or subtable) to modules in the resource tables. Since at least some of these modules are dynamic modules created by mods, I have to do this in postRunFn.

I can change the values of existing fields in a module no problem by direct assignment (for example module.order.value = 7 etc works okay).

But I get crashes/errors when I try to add a new field or a subtable to an existing field (for example module.fluffy = "meow" or module.metadata.myParams = { first = "red", last = 42, } etc). I tried table.insert and it doesn't work either. I also tried it in-game with console api commands (on a new module table made with type..new command) and it doesn't work there either.

I thought I was just messing up syntax because n00b, but after hours of testing I realized that I can only edit values of existing fields, or add new elements into existing subtables. I can't add new fields or new subtables.

Is this correct? Is there a way around this?

Note I have successfully added new fields/subtables into actual .module files for "static" modules that have them, so I know that module resources are capable of using custom fields. It's only in the api interface that I seem unable to do similar.

Thanks!
< >
Showing 1-4 of 4 comments
lollus 15 10 Jun, 2024 @ 4:12pm 
The api is full of crap :-) Does it work if you make a copy of a module, then set the original as invisible?
RadiKyle 6 10 Jun, 2024 @ 4:45pm 
😂

Naw that idea didn't work either. In the console I used api.type.ModuleDesc.new, which creates a new module table, but I was still unable to add new fields/subtables to it, I could only edit the existing ones. 🤷‍♂️
lollus 15 16 Jun, 2024 @ 3:57pm 
Not all tables work the same because the api does not always mirror them properly from c++ to lua. You may get lucky with different techniques, like using indexes. Trial and error is required. Some tables might not work at all :-)
RadiKyle 6 16 Jun, 2024 @ 4:04pm 
Probing in the dark... fun lol
< >
Showing 1-4 of 4 comments
Per page: 1530 50