Where am I supposed to put Modifiers in Scripts?

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


  • for the last week I have been running tests trying to understand how it modding in TF2 works, and I gotta be honest: even though I have read all the wiki multiple times and have read tons of threads and downloaded several mods and studied them and even though i have easily made mods for other games in the past TF2 is very irritating to work with.


    Now I have a very simple script and I just can't figure out where to put the line "addModifier("loadConstruction", ModifyFarm)", I have tried at the begining, the end, in the update function, first line of the modifyfarm function, in between data and the function in between the brackets of the data function, as an init function, and nothing works, the game always crashes because "data" is nil (and local).



    Another question: is it possible to use postRunFn or runFn in scripts? or is it just for the mod.lua? and if so, where should i put it? the modding wiki doesn't explain much.

  • both the postRunFn and the runFn are exclusively in the mod.lua


    The addModifier call belongs into the runFn.

    thanks for the reply. (sigh), that's not even how they show it in the wiki, there they just put it at the end as a standalone line.

    I really don't want to bother people here with every little detail but the truth is that I thought I would be done by now, but since certain things are only available in scripts, some are only available in the gui thread some in the engine thread, some only in the mod.lua and syntax sometimes confuses me: everything seems more complicated than it needs to. But if you will indulge me, I have 1 more question:

    - I created a script that uses the update function of the engine thread to assign the current-year to a variable,

    - I want that to run a series of if statements to modify values of industries (and some other things) at certain years
    Q: if I cant use the addmodifier in the script in which I get the year, and if I can't get the year in the mod.lua, and if i can't bring variables from scripts to mod.lua (I was told), can I bring a variable or function from the mod.lua to the script? and if so how?


    thanks again

  • The output of industries is dependent on three factors:

    Demand - output will gradually rise or fall to meet the demand that our transport lines connect the industry to.

    Supply - output will be limited by the raw materials available, if applicable. Again, the user controls the availability with transport lines.

    Neither of these can be influenced programatically, other than by changing the supply rules.

    The third factor is a hard limit, imposed by the "level" variable.

    Changing the supply rules, or the level variable, requires, at a minimum, invoking the updateFunction in the industry's construction file. Changing the supply rules may require more than that - I'm not sure.

    You might want to have a look at the following:

    https://steamcommunity.com/sha…iledetails/?id=1967520065

    https://steamcommunity.com/sha…iledetails/?id=1970151023

    The first of these is doing essentially what you're looking to do - change the production level of the indstry in question. (You don't need to call the setPlayer function that this mod does.)

    The second changes the number of production levels available for each industry. It does so by implementing a modified version of industryutil.lua

  • I appreciate the response, but none of these mods help me with what I want to do (and I think you forgot our past conversation also because I already did all the industry modification in another script).


    all that's missing is to change the variable "year", to a dynamic variable that updates automatically. You helped me how to create that gamescript that gets said variable, but I haven't found the way to USE that variable with my industry modifiers. You told me that I should migrate the whole thing from mod.lua to the new gamescript and that way I could use them together and after a while of trying every single combination I could think of I started this thread where I learned that no, I can't migrate the mod.lua to the gamescript.


    So my question is: how do I integrate these two things?

  • construction updateFn params should include the year (params.year)

    thanks, that was another question that I asked at one point, if the parameter "year" of the industry updateFn function would do the same (and since I've been burned by the wiki several times before I don't know what to think anymore jaja)

    I also found out by studying the sensless industries mod that I can add modifiers to variables in scripts directly from the mod.lua , which is probably what Doug was trying to tell me about. what I like about this solution is that instead of having 1 huge mod.lua i can break apart my tasks into 3 different scripts.

    I'll give it a try and hopefully, I'll be able to publish soon.


    thanks again

BlueBrixx