Variables
Variables (in Europa Universalis IV) are persistent values that are either associated with a specific country or province.
Using variables[edit | edit source]
![]() |
Please help with verifying or updating this section. It was last verified for version 1.23. |
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 number 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 variable[edit | edit source]
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 variable[edit | edit source]
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 fixed-point decimals (they're precise to the nearest thousandth), meaning you can increment with decimal values as well.
All of the variable operation effects are:
change_variable # Add subtract_variable # Subtract divide_variable # Divide multiply_variable # Multiply
Check the variable[edit | edit source]
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 variable[edit | edit source]
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 variables[edit | edit source]
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 } } }
Effects[edit | edit source]
The effects related to variables:
set_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, sets the first <var> to the second <var>'s value / <scope>'s value of <var> }
change_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, adds the second <var> to the first <var> / <scope>'s value of <var> to the current scope's <var> }
subtract_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, subtracts the second <var> from the first <var> / <scope>'s value of <var> from the current scope's <var> }
divide_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, divides the first <var> by the second <var> / <scope>'s value of <var> }
multiply_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, multiplies the first <var> with the second <var> / <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> }
Triggers[edit | edit source]
The triggers related to variables:
check_variable = { which = <var> value = <number> which = <var> / <scope> # Used in place of value, checks if the first <var> is equal or higher than the second <var> / <scope>'s value of <var> } is_variable_equal = { which = <string1> which = <string2> }
Variable Arithmetic Trigger[edit | edit source]
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 lets 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 Values[edit | edit source]
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 an 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 Values[edit | edit source]
Country[edit | edit source]
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, decimals 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.
|
Province[edit | edit source]
Value | Notes |
---|---|
modifier:<province modifier> | The modifier:<modifier> syntax works for any province modifier.
|
trigger_value:<trigger> | The trigger_value:<trigger> syntax works with triggers than return integers, decimals 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 | Effects • Triggers • Modifiers • Scopes • Variables • Localisation • Customizable localization • Run files |
Scripting | Scripted function • Advisors • Ages • Bookmarks • Buildings • Casus belli • Colonial regions • Countries • Culture • Decisions • Defines • Diplomatic actions • Disasters • Empire of China • Estates • Events • Factions • Government • Great projects • History • Holy Roman Empire • Idea groups • Institutions • Mercenaries • Missions • Modifiers • Nation designer • On Actions • Parliament • Peace treaties • Policies • Rebel types • Religion • Subject types • Technology • Trade companies • Trade goods • Units |
Map | Map • Nation designer • Random New World • Trade nodes |
Graphics | 3D Models • Interface • Graphical Assets • Fonts • Particles • Shaders • Unit models |
Audio | Music • Sound |
Other | Console commands • Checksum • JoroDox mod making tool • Mod structure • Troubleshooting • The Validator • Run files |
Guides | Adding a province • Save-game editing |