Cargo type definitions location

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


  • In TpF1 the game cargo types were defined in game.config.cargotypes but that is no longer present in TpF2. I see the cargo types are defined in \res\config\cargo_types\ but how do I enumerate them in my mod? Previously it was as simple as

    Code
    for i=1,#game.config.cargotypes do


    but I'm not sure what to do in TpF2?

  • You can't in TPF2. Its now like the other gameresources like vehicles where you have to register a modifier function where can apply changes. I have it not open currently but i think it was named "loadCargoType". Just search for the definition of all the possible modifiers of the game.


    MFG PMV

  • Perhaps an example might help?


    Previously I was doing something like this:

    Code
    for i=1,#game.config.cargotypes do
    	if (game.config.cargotypes[i].id == "MIXED_FODDER") then
    		-- MIXED_FODDER cargo type has been defined, do something about it
    	end
    end

    Now how would I do a similar thing in TpF2?

  • Lua
    addModifier("loadCargoType",
        function(fileName, data)
            -- write your code here
            return data
        end
    )

    und die Parameter die die Rückruffunktion bekommt:

  • OpenSource: thank you, that helps. But I'm still having problems with lua scoping issues.


    I'm currently trying to get the list of defined cargo types:

    Lua
    definedCargoTypes = {}
    addModifier("loadCargoType", function(fileName, data)
    	table.insert(definedCargoTypes, data)
    	return data
    end)
    -- definedCargoTypes is empty here

    And it does indeed loop through the cargo types, add them into definedCargoTypes (if I check the value inside the anonymous function the table gets one entry longer each time), but when I want to do something with it on the next line beyond the addModifier call, the table is empty. What am I doing wrong?

  • Different Lua States

    Lua
    definedCargoTypes = {}
    print("before addModifier", definedCargoTypes , os.clock())
    addModifier("loadCargoType", function(fileName, data)
     print("in addModifier", definedCargoTypes , os.clock())
     table.insert(definedCargoTypes, data)
     return data
    end)
    print("after addModifier", definedCargoTypes , os.clock())
    -- definedCargoTypes is empty here


    Lua; states, threads, libraries and memory layout: http://www.thijsschreijer.nl/blog/?p=693

BlueBrixx