Problem with adding Multiple units at postRunFn

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


  • 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:


    Code
    local MuVariantRecord = api.type.MultipleUnit.new() -- create an api type, here - a multiple unit
    
    -- show its fields
    debugPrint( MuVariantRecord )
    -- show its metadata - which includes methods   
    debugPrint( getmetatable( MuVariantRecord ) )
                
BlueBrixx