Problem with adding Multiple units at postRunFn

Willkommen in der Transport Fever Community

Welcome to the fan community of Transport Fever and Train Fever, the economic simulators of Urban Games. The community is free for you to share and inform yourself about the game. We cultivate a friendly and objective interaction with each other and our team will be happy to answer any questions you may have.


Registration and use is of course free for you.


We wish you a lot of fun and hope for active participation.

The Team of the Transport-Fever Community

  • It appears I am spamming the forum :)

    I have a problem. I've been sitting at it for the last few days and am stumped. The API reference does not help much, but the wiki mentions that adding mutliple units at runtime should be possible - at the 'postRunFn' stage. Brilliant for my use case. So I wrote this code:

    What I am trying to do is to take an existing MU and add several variants of it using different models. The problem I am facing is that I don't know how to add stuff ot the vehicles array. So far I tried to use the 'table.insert', use an index starting from 1 or from 0 and even regular c++ code.

    I gather that I should use some sort of an api call for the engine to allocate the memory for the MU component for me. But I dumped the api and api.type arrays and did not find any relevant function. Scouring the game provided scripts gave me nothing. What am I missing?

    EDIT: the creation of the vehicle array does not seem to change anything.

  • This works:

  • doug: THANK YOU! This solves my problem. Also, for the brave soul out there who might have this or similar issue in the future ( and google catches this ). In order to get the members of an api.type use code like this:

    1. local MuVariantRecord = -- create an api type, here - a multiple unit
    2. -- show its fields
    3. debugPrint( MuVariantRecord )
    4. -- show its metadata - which includes methods   
    5. debugPrint( getmetatable( MuVariantRecord ) )