Wo ist game.interface?

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

  • Wollte grade eine meiner Mods für TPF2 testen, wo die momentane Gesamtbevölkerung gezählt werden muss.
    Früher ging das über game.interface.getTowns() aber offensichtlich fehlt bei TPF2 das gesamte game.interface.

    Habe auch bisher eine Übersicht oder ein Modding-Wiki vermisst wie es das bei TPF1 gab (http://transportfever.com/wiki…dules/game.interface.html)

    Man muss die Dinge so einfach wie möglich machen. Aber nicht einfacher. - Albert Einstein

  • game.interface.getTowns() gibt es. Es sind aber nicht alle Interfaces über alle "Threads" nutzbar. In einem game_script unter update (alles was nicht UI ist, sollte es nutzbar sein)
    CommonAPI2 Console kann in alle aktiven lua_States reinschauen. commonapi.dmp(<variable>) zur Ausgabe und es gibt auch Tab Completion. (Als erstes muss aber der "Thread" bzw. luaState im Linken Dropdown ausgewählt werden.

    Im CommonAPI2 Lua State ist das zum Beispiel natürlich nicht vorhanden...

  • this worked in TPF1.

    I dont know how to get it working in TPF2.

    Man muss die Dinge so einfach wie möglich machen. Aber nicht einfacher. - Albert Einstein

  • Thanks for your answer Vacuum Tube.
    I do have no experience with TF1.
    From the Lexicon, iIt seems that in TF1, the datas that were displayed were much more complete: Data structures returned by game.interface

    Thanks to eis_os , I do now know did in TF2 It Seems that die game.interface.getTowns does return to ID and game.interface. GetEntity does return a few datas.

    That is both in the Scrip thread or the GUI thread.

    HOWEVER, there is a table with every town's statistics accessible through the GUI, so I'm crawling through the game's files to see how it's done. EDIT: it's always after a post is sent did something new comes up! : D

    Addendum: Referring to [user = '37457'] CLEMARC [/ user] 's entry in the Lexicon: Create Mod with GameScript

    getTownCapacities output 3 figures which are, respectively: that town's amount of residents, shopping facilities and workplaces.

    using CommonAPI's console:
    1. commonapi.dmp (game.interface.getTowns ())
    2. commonapi.dmp (game.interface.getEntity (2058)) --so I know what's what
    3. commonapi.dmp (game.interface. getTownCapacities (2058))


  • Hello, comrades.

    There is a same questions.

    I watch "GameScript" Lexicon thread, but still don't get, where i need to call game.interface callbacks? I mean is it needed to be created in game_script/some-name.lua file? I need to make separate functions or insert it into update function? How I can call that function from my scripts?

    I already try to call game.interface from my script, there is nil value returned

    I try from update function of game_script/some-name.lua - and there is nothing happens, even answer for game.interface nil check.

    I try from separate function of game_script/some-name.lua still nothing.

    I try to call separate function of game_script/some-name.lua from my external script - and i cant register my gamescript as util script holder.

    P.S. I know nothing about coding, start luring few days ago, make "industry workers" mod, but it was simple. Now i wanna expand it, make usable UI for it with complied data about available and filled workplaces to make passenger logistic clearly. Now, coas of there is no autobalancing we have to much amount of workplaces (coas towns have their own workplaces for all the population and new workplaces in industries is additional, so we have not enough population for all the workplaces) and asset-placed residential buildings also have no visible UI to watch how many living places are you added.

    So, for the beginning i need to use, but cant reach no of this functions:

    1. -- getIndustryProductionLimit
    2. -- getTowns
    3. -- getTownCapacities
    4. -- getTownReachability
    5. -- getBuildingType
    6. -- getBuildingTypes
    7. -- getEntities
    8. -- getEntity
    9. -- getLines
    10. -- etc.

    My test function:

  • Ok, nice to know.

    However, the problem with my mod is, that I'm calling that function in addModifier in runFn and in this mod thread game==false, so game.interface is not available.

    Maybe I need to combine that with the new GameScript, but dont know how yet.

    The 'game' variable is available in the runFn function of a mod. However, the modifier function, even if it is defined inline within runFn, does in fact run in a different thread - a thread where 'game.interface' is not available.

  • Is there no possibility to access game.interface in a addModifier function? I have another mod where I need a function from game.interface in the updateFn of a construction... also nil there.

    I haven't fully understand the new thread concept yet. In TPF1 this was no problem, there was just one thread and everything was available everywhere. Maybe they did it for performance reasons, but I don't think the lua part is the critical part regarding performance. At the moment, I think it caused more problems than it helps.

    So does anyone know if it is possible to switch threads somehow? Or is there a interface we don't know?

    Maybe it's somehow possible to pass the game variable to addModifier via parameters?

    SpaceCossaX: nice idea, your mod. But keep in mind that the modding tools for UI are very limited.

    Man muss die Dinge so einfach wie möglich machen. Aber nicht einfacher. - Albert Einstein

  • Modifiers are executed when TPF2 loads a resource, they run when starting the game, there aren't any towns there.

    1. TPF(1/2) reads a lua file or construction
    2. runs all modifiers for this type
    3. Reads the "modified" into it's C++ structures. (no lua code run after that, except update function is stored)
    4. TPF2 destroys the loading lua state (thread)

    Even in TPF1 you couldn't access the town or map when loading say a track.

    The only sane place for game.interface related code is in a game script, there you can observe what a construction does, any maybe interact with it via upgradeConstruction.

    Enzojz does this.

    CommonAPI2 can't call into the lua states, as this very tricky. At least from the rendering thread.

    To be exact, CommonAPI2 native internals provides some primitives to get data from one thread/lua state to the other (commonapi.repos data), but that is complete different story all together...

  • The 'Start Paused' mod I posted a couple of days ago uses a game script file. There are actually two files needed - one in 'res/config/game_script' that loads the other, which is located in 'res/scripts'

    It is this second file that contains the actual functions that will be called on each update or event.