Open main menu

Variables

Variables (in Europa Universalis IV) are persistent values that are either associated with a specific country or province.

Contents

Using variablesEdit

Variables can operate in country and province scopes, and in both effect and trigger contexts, although the commands and conditions used in either context differ.

For example, if we wanted to track the number of times an event occurs for a country we'd want to use a variable.

Note 1 : there is a maximum size of float that a variable can hold. Values over 2,147,484 will overflow into the negative.

Note 2 : variables can not be used as right side arguments (in an effect section for instance) except for religion and culture (see Event Scope Value section below)

Setup the variableEdit

To associate a variable with a country (or province), you first need to set the variable.

set_variable = {
    which = myCountingVariable
    value = 0
}

Typically you'll want to do this in a setup event, i.e. an event that fires only once at the start of the game. You can do this fairly easily by using the on_startup on action and an event that checks for has_country_flag and sets it in the immediate section.

Increment the variableEdit

Having set your variable, you can now use the variable operation effects. So, in this theoretical event, we would add the following to the immediate section:

immediate = {
    change_variable = {
        which = myCountingVariable
        value = 1
    }
}

This increments the myCountingVariable by 1. Variables are floats, meaning you can increment with non-integer values as well.

All of the variable operation effects are:

change_variable             # Add
subtract_variable           # Subtract
divide_variable             # Divide
multiply_variable           # Multiply

Check the variableEdit

Now we can track this event's occurrence, we now want to execute a different event when the variable reaches 5. To do this, we will have to utilise the variable comparison triggers in the event's trigger section.

Here is how you would check the variable value is 5 and more:

check_variable = {
    which = myCountingVariable
    value = 5
}

To check if the variable is exactly 5, you'll want to include another inverted check_variable:

check_variable = {
    which = myCountingVariable
    value = 5
}
NOT = {
    check_variable = {
        which = myCountingVariable
        value = 6
    }
}

Localising the variableEdit

We can localise the variable so it appears as a string we have defined, rather than the variable script name.

 myCountingVariable: "My Counting Variable"

In a different event, we may want to display this variable to the player in the event description. To do so, you can include the following localisation command:

 event_desc: "[Root.myCountingVariable.GetName] [Root.myCountingVariable.GetValue]"

The Root here refers to the ROOT scope of the event. The localisation commands here use the myCountingVariable associated with ROOT and display the localised string (with GetName) and the current value for ROOT (with GetValue).

Exporting variablesEdit

Variables can be filled with the values of exported internal values. This means game values such as monthly_income can be exported to a variable and then used in various manners. Additionally, variables can be compared to other variables, which is very useful when they contain exported values, allowing for comparison that may otherwise not be possible.

Let's say we want to make an event that gifts money depending on the country's monthly income but doesn't exceed the country's treasury. To do this we first need to export two variables in the event's immediate section:

export_to_variable = {
    which = moneyToGive
    value = monthly_income
    who = ROOT
}

export_to_variable = {
    which = moneyAvailable
    value = treasury
    who = ROOT
}

We then want to multiply the country's income by six to reach our gift amount:

multiply_variable = {
    which = moneyToGive
    value = 6
}

To ensure the gift size isn't larger than the country's treasury, we will clamp the gift size to the country's current treasury amount, if the gift size is larger than it:

if = {
    limit = {
        # Is moneyToGive greater than moneyAvailable
        check_variable = {
            which = moneyToGive
            which = moneyAvailable
        }
    }
    
    # Set moneyToGive to moneyAvailable's value, as moneyToGive was greater than moneyAvailable
    set_variable = {
        which = moneyToGive 
        which = moneyAvailable 
    }
}

Then in the event option add the scaling add_treasury, depending on the moneyToGive value:

option = {
    if = {
        limit = { 
            NOT = { check_variable = { which = moneyToGive value = 25 } }
        }
        add_treasury = -10
        FRA = { add_treasury = 10 }
    }
    if = {
        limit = { 
            check_variable = { which = money_to_give value = 25 }
            NOT = { check_variable = { which = moneyToGive value = 50 } }
        }
        add_treasury = -25
        FRA = { add_treasury = 25 }
    }
    if = {
        limit = { 
            check_variable = { which = money_to_give value = 50 }
            NOT = { check_variable = { which = moneyToGive value = 100 } }
        }
        add_treasury = -50
        FRA = { add_treasury = 50 }
    }
}

EffectsEdit

The effects related to variables:

set_variable = {            
    which = <var>
    value = <float>
    which = <scope>         # Used in place of value, makes <var> the <scope>'s value of <var>
}
change_variable = {            
    which = <var>
    value = <float>
    which = <scope>         # Used in place of value, makes <var> the <scope>'s value of <var>
}
subtract_variable = {            
    which = <var>
    value = <float>
    which = <scope>         # Used in place of value, makes <var> the <scope>'s value of <var>
}
divide_variable = {            
    which = <var>
    value = <float>
    which = <scope>         # Used in place of value, makes <var> the <scope>'s value of <var>
}
multiply_variable = {            
    which = <var>
    value = <float>
    which = <scope>         # Used in place of value, makes <var> the <scope>'s value of <var>
}
export_to_variable = {
    which = <var>               # e.g., stabilityVar
    variable_name = <var>       # same as which, alternative declaration
    value = <string>            # e.g., stability
    who = <scope>               # Who to grab the value from
    
    # Supports exporting trigger limit values. Works for int, float and boolean triggers
    value = trigger_value:<trigger>
}

TriggersEdit

The triggers related to variables:

check_variable = {
    which = <var>
    value = <float>
    which = <var>       # Used in place of value, checks value of the first <var> against the value of second <var>
}

is_variable_equal = {
    which = <string1>
    which = <string2>
}

Variable Arithmetic TriggerEdit

Used within triggers to export variables whilst in a trigger scope.

Here is a common example:

variable_arithmetic_trigger = {
    custom_tooltip = <string>
    
    # Exports must be done before triggers
    export_to_variable = {
        variable_name = <string1>
        value = <var>
    }
    
    export_to_variable = {
        variable_name = <string2>
        value = <var>
    }
    
    # Normal triggers are valid here
    <triggers>
    
    # Var1 == Var2
    is_variable_equal = {
        which = <string1>
        which = <string2>
    }
    
    # Var1 >= Var2
    check_variable = {
        which = <string1>
        which = <string2>
    }
}

This is useful if you want to compare certain triggers against one another. For example, let's say you want to check if your ruler is older than a foreign heir. We have ruler_age and heir_age triggers, but you cannot do this: ruler_age > FROM = { heir_age }.

However, a variable arithmetic trigger let's you do this.

variable_arithmetic_trigger = {
    custom_tooltip = HAS_OLDER_RULER_THAN_THEIR_HEIR
    
    export_to_variable = {
        variable_name = my_age
        value = trigger_value:ruler_age
    }
    export_to_variable = {
        variable_name = their_age
        value = trigger_value:heir_age
        who = FROM
    }
    
    ruler_age = 0
    FROM = {
        heir_age = 0
    }
    
    check_variable = {
        which = my_age
        which = their_age
    }
}

Event Scope ValuesEdit

Event scope values are used to reference the index of a variable to a culture or religion. This occurs when you export a culture or religion with export_to_variable.

Whilst the actual value of the variable remains is a number, this number is an index of the culture or religion's location in their respective list. This index is transformed into the correct culture or religion when used with certain effects and triggers.

To export variables for this, you need to use this syntax:

export_to_variable = {
    variable_name = myVarName
    value = <export value>
}

To use the variable with the effect or trigger, you use this syntax:

set_heir_culture = variable:myVarName

This syntax supports FROM, meaning you can scope to a province and use FROM inline to scope to the country where the variable was exported.

any_owned_province = {
    culture = variable:From::myVarName
}

Additionally, in triggers you can use this syntax to grab a export values for comparison:

religion_group = new_variable:ruler_religion

This allows you to check export values within triggers (since export_to_variable is an effect).

Supported effects:

change_religion
change_culture
change_primary_culture
set_ruler_culture
set_ruler_religion
set_consort_culture
set_consort_religion
set_heir_culture
set_heir_religion

Supported triggers:

ruler_culture
consort_culture
heir_culture
ruler_religion
consort_religion
heir_religion
culture
religion

Exportable ValuesEdit

CountryEdit

Value Notes
modifier:<country modifier> The modifier:<modifier> syntax works for any country modifier.
trigger_value:<trigger> The trigger_value:<trigger> syntax works with triggers than return integers, floats or booleans. More complex triggers do not work.
prestige
war_exhaustion
corruption
stability
treasury
mercantilism
inflation
num_of_cities
num_of_ports
adm_tech
dip_tech
mil_tech
years_of_income
monthly_income
trade_income_percentage
states_development
total_development
average_autonomy
average_home_autonomy
manpower
manpower_percentage
max_manpower
land_forcelimit
naval_forcelimit
army_tradition
navy_tradition
army_size
navy_size
average_unrest
average_autonomy_above_min
average_effective_unrest
num_of_rebel_armies
num_of_rebel_controlled_provinces
overextension_percentage
ADM Current ruler ADM skill
DIP Current ruler DIP skill
MIL Current ruler MIL skill
consort_adm
consort_dip
consort_mil
heir_adm
heir_dip
heir_mil
monarch_age
consort_age If no consort exists, the current in-game year minus 1 is returned.
heir_age If no heir exists, the current in-game year minus 1 is returned.
patriarch_authority
piety
religious_unity
tolerance_to_this Refers to Tolerance of the True Faith
religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
dominant_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
secondary_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
ruler_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
heir_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
consort_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
adm_advisor_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
dip_advisor_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
mil_advisor_religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
primary_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
dominant_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
ruler_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
heir_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
consort_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
adm_advisor_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
dip_advisor_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
mil_advisor_culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
border_distance Requires the use of who = <scope> in the export_to_variable to work correctly.
capital_distance Requires the use of who = <scope> in the export_to_variable to work correctly.
opinion Requires the use of who = <scope> in the export_to_variable to work correctly.
trust Requires the use of who = <scope> in the export_to_variable to work correctly.

ProvinceEdit

Value Notes
modifier:<province modifier> The modifier:<modifier> syntax works for any province modifier.
trigger:<trigger> The trigger:<trigger> syntax works with triggers than return integers, floats or booleans. More complex triggers do not work.
base_tax
base_production
base_manpower
development
unrest
nationalism
local_autonomy
province_trade_power
tolerance_to_this Refers to Tolerance of the True Faith
culture Returns an index value, i.e. 1 for English, 2 for French, etc. Value is converted to proper culture when used with correct effects and triggers.
religion Returns an index value, i.e. 1 for Catholic, 2 for Protestant, etc. Value is converted to proper religion when used with correct effects and triggers.
Documentation EffectsTriggersModifiersScopesVariablesLocalisationCustomizable localization
Scripting AdvisorsAgesBookmarksBuildingsCasus belliColonial regionsCountriesCultureDecisionsDefinesDiplomatic actionsDisastersEstatesEventsFactionsGovernmentGreat projectsHistoryIdea groupsInstitutionsMissionsModifiersNation designerPoliciesReligionRebel typesSubject typesTechnologyTrade companiesTrade goodsUnits
Map MapRandom New WorldTrade nodes
Graphics 3D ModelsInterfaceGraphical AssetsFontsParticlesShadersUnit models
Audio MusicSound
Other Console commandsChecksumJoroDox mod making toolMod structureTroubleshootingThe Validator
Guides Adding a province