1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Is it possible to set a value as a function of a variable?

Discussion in 'Mod Creation Help' started by ReggieB, Jun 3, 2019.

  1. ReggieB

    ReggieB Chieftain

    Joined:
    Mar 28, 2018
    Messages:
    26
    Gender:
    Male
    Hi all, I have what might be a strange question. I can think of several different mod ideas that are held back by the fact that I don't know how (or if its even possible) to set a value as a function of some other variable. I think it would be easiest to explain what I mean with an example.

    Suppose I want to make a mod that grants each city a 2% growth bonus per population of the city. The only way I know of to do that is to create one modifier that grants a 2% growth bonus if the city has at least 1 population, then make a second modifier that grants an additional 2% growth bonus if the city has at least 2 population, and so on up until there is one modifier for every possible population of a city.

    It seems like it would be much more easy and reliable if I could just make one modifier that gives a city a growth bonus of "2*x, where x = city population". Is something like this possible with the games modifier system? If so, could someone recommend a good guide or example of how it is done? If that type of this is not possible, are there any clever workarounds that can achieve the same result?
     
  2. raen

    raen Coat of Arms

    Joined:
    May 12, 2003
    Messages:
    2,153
    Location:
    Portugal
  3. ReggieB

    ReggieB Chieftain

    Joined:
    Mar 28, 2018
    Messages:
    26
    Gender:
    Male
    Can Lua be used to update modifier arguments dynamically? In my example, would there be a Lua function that could change the "amount" of the growth bonus automatically (and set to a different number for each city)? Or do you mean that you would recommend using Lua script to change the growth bonus of a city without even using a modifier? Either way, I would appreciate any guides or examples you could recommend on the subject.
     
    Last edited: Jun 13, 2019
  4. raen

    raen Coat of Arms

    Joined:
    May 12, 2003
    Messages:
    2,153
    Location:
    Portugal
    My solution would be totally with lua, you can have your variables and calculation by city, when ready to grow you change population. But probably possible by modifiers, I dont know.
     
  5. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    6,234
    Location:
    Illinois, USA
    Lua cannot alter anything in the database.

    Modifiers can be constructed that take into account for example city population, but it requires multiple modifiers, each with a differing "at least" value within the requirements of the individual modifiers.

    The game's database is not dynamic in the sense of being able to alter the data in the database once the game has commenced. The values entered into the database at loading of the base-game and then loading of DLC, Expansion, and Mods, is fixed for the remainder of that game-session. The game's DLL calculates the alteration of in-game values that are applied based on the static values within the database and does multiplication as needed based on number of previous copies of a unit or district that have been created (or what have you), but the base value seen within the SQL database is not altered and is not alterable while in game-session.

    Gathering Storm allows us to directly attach any modifier via lua scripts to a player or a city, but we cannot as yet take them away, nor can we attach them to units.
     

Share This Page