Is there a way to change a property of a CONSTRUCTION entity?

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!


    I built a lot of houses with an old mod. Many houses have a huge personCapacity without cars.

    I plan to run a script that reduces the personCapacity to 1 or 0 if the BASE_EDGE property is empty.


    Is there a way to change the property of a CONSTRUCTION entity?


    Thank you in advance for your answer!

  • All right! And how can I upgrade? Is there an example of that?


    Should I read the constructs to an array and update them in a cycle?

    I can read the constructions. But I'm not sure how I can update them. :/

  • I tried but got an error. :(

  • Only the script thread is allowed to modify the entity system and sendCommand (or better say, the Command will be later executed)


    I cannot sync to UG lua threads, so it's a bit tricky for crowded lua threads


    And if you don't report bugs, they won't be solved...

  • If I run this code in the Script Thread, I get the information about a construction.

    Code
    commonapi.dmp (game.interface.getEntity(8546))

    If i run this than i don't get any error:

    Code
    local building = commonapi.dmp (game.interface.getEntity(8546))

    But i can't read or print the "building" variable. I got this error when i try it:

    Code
    [string "building"]:1: syntax error near <eof>

    I don't know that this varieble has values or not.

    I tried this also but I got an error:

    Code
    commonapi.dmp (game.interface.upgradeConstruction(building.id, building.fileName, building.params))
    
    Console::Execute: [string "commonapi.dmp (game.interface.upgradeConstruc..."]:1: attempt to index global 'building' (a nil value)

    I don't know that how should i use the commonApi.

    Could anyone write an example of a code that upgrades a construction? Please!

    I think after that I can finished it.

  • commonapi.dmp won't return anything, it dumps data, nothing more.


    local building = game.interface.getEntity(8546)

    commonapi.dmp(building)

    local result = game.interface.upgradeConstruction(building.id, building.fileName, building.params)

    commonapi.dmp(result)


    Note: as the script thread is run a lot, a one liner is likely to have higher success rate:


    local building = game.interface.getEntity(8546); game.interface.upgradeConstruction(building.id, building.fileName, building.params)

  • First of all thank you for your help!

    I tried this in the commonApi Script Thread:

    Code
    local building = game.interface.getEntity(8546); game.interface.upgradeConstruction(building.id, building.fileName, building.params)

    I got this:

    Second attempt:

  • Well it looks like some internal state broke, likely the upgradeConstruction doesn't like your params.

    Sample, you aren't allowed to pass a seed in param.


    Update von Konstruktionen - SimpleProposal


    Please note: That isn't commonapi script thread, it's a TPF2 lua state.


    That is the lua state used by all config/game_script/*.lua non ui related callbacks = Engine State described by UG

    GUI Thread = GUI State as described by UG


    There are two states created and handled by CommonAPI itself, the CommonAPI Main LUA => used by the CommonAPI UI Overlay

    CommonAPI Game Env => used as bridge between UG and CommonAPI World, mostly unused



    CommonAPI2 injects commands to the LUA States, but I have no control on them, so if it's running currently, it may crash badly or it's internal state goes out of control.

    Yes, that it's not nice, and I know it should be better. But until the modding Update, neither TPF1 nor TPF2 had any access to a console at all.

  • This code is the winner:

    Code
    local building = game.interface.getEntity(8546); building.params.seed = nil; game.interface.upgradeConstruction(building.id, building.fileName, building.params)

    Thank you for your help!!

BlueBrixx