Skip to content

Variables

github-actions[bot] edited this page Jun 17, 2026 · 23 revisions

Table of Contents



This Wiki page was last updated for $$\textcolor{aqua}{Stellaris}$$ version v4.4.*



1. Wiki Section

See https://stellaris.paradoxwikis.com/Variables

2. From Stellaris Game Files

2.1. common/scripted_variables/00_scripted_variables.txt

Add global variables here (common/scripted_variables/) that will be available in all script files.

@something = 42

They can be overridden in each normal script file.

2.2. From events/000_how_to_use_variables_in_script.txt

2.2.1. THE GRAND VARIABLES GUIDE

As of version 3.1, you can now do fancy things with variables in script. This is a short write-up of what exactly you can do. (For exact formatting of effects and triggers mentioned, see logs/scripting_documentation)

2.2.2. Checking Variable Values

  • When you are using the value of a variable, you can now use dot scoping. E.g. value = owner.capital_scope.my_variable
  • You can also directly refer to the value of a trigger, e.g. value = trigger:pop_amount
  • A combination of the two is also possible: `value = owner.capital_scope.trigger:pop_amount
  • Similarly, you can check the value of modifiers applying to this scope: value = modifier:pop_citizen_happiness
  • And you can use script values defined in common/script_values via value:my_value
  • This works almost everywhere where you are using variables. The exception is in the basic variable effects and triggers where you are specifying which variable to check or change.

2.2.3. Setting Variables

You can make a variable out of various numbers. The easiest is set_variable and change_variable, but you can also do:

  • get_galaxy_setup_value: galaxy setup options
  • export_trigger_value_to_variable: the value of a trigger (e.g. number of pops in the empire). Should work for all triggers that are comparing a single numerical value. For triggers with , you can specify parameters =
  • export_modifier_to_variable: the sum of the specific modifier applying to this scope, e.g. the amount of pop_citizen_happiness that a pop is gaining from all sources (including any country and planet modifiers).
  • export_resource_income_to_variable, export_resource_stockpile_to_variable: country's monthly income or current stockpile of a resource

2.2.4. Manipulating Variables

Once the variable is set, you can then alter it with standard mathematical operations: change_variable (addition, subtraction), multiply/divide/modulo_variable, etc.

Rounding has several options: round_variable will round to the closest integer, floor/ceiling_variable will round it down or up respectively. round_variable_to_closest will let you round to a multiple of the specified value

In all of these effects except round/floor/ceiling_variable, you can add/multiply/whatever the variable by another one, with dot scoping and referring to triggers allowed. E.g.:

multiply_variable = {
    which = my_var #must be directly referring to a variable
    value = fromfromfrom.owner.trigger:pop_amount
}

Once you are done with a variable, you can clear it using clear_variable.

Also worth noting: if you need to manipulate a variable in a trigger, you can use the check_variable_arithmetic trigger (which now supports an unlimited number of add/subtract/divide/multiply/modulo operations)

2.2.5. Using Variables - The Wheres

We can now use variables in a lot of different places:

  • Any trigger that is comparing a single number, including ones with . E.g. pop_amount > my_variable, intel = { who = from value < trigger:pop_amount }
  • Any effect using a single number, including ones with . E.g. add_experience = my_variable.
  • The count parameter of while loops!
  • Certain effects let you input variables for various reasons. E.g. multiplier on add_modifier (the modifier's bonuses will be multiplied by the variable), mult on add_resource (multiplies all resources granted by that effect)
  • Triggered resource tables can take a multiplier = <variable>:
    resources = {
        category = planet_buildings
        cost = {
            trigger = { <triggers> }
            minerals = 100
            multiplier = my_var/trigger:pop_amount
        }
    }
  • MTTH/AI Chance modifiers:
    ai_chance = {
        factor = 1
        modifier = {
            add/factor = my_var/trigger:pop_amount
            is_variable_set = my_var
        }
    }
  • Triggered modifiers:
    triggered_pop_group_modifier = {
        potential = { stuff }
        modifier = { stuff }
        mult = value:my_value
    }
    
  • Ordered script lists: scope to the country with the highest (or 3rd highest, or lowest) value for a variable or trigger.
  • In locs: if you refer to [This.my_variable], it will print the value of the variable, so long as the variable is set.

3. From Discord (Stellaris Modding Den)

See Discord > Stellaris Modding Den > This Post)

3.1. Using Scripted Variables & Inline Scripts for Mod Compatibility:

Convention is 1 for a present mod, 0 for an absent mod.

These variables can be used to create content conditional on other mods as follows (credit to TTFTCUTS for this invention):

  1. in your Target file to use Conditional Code:

    inline script = {
        script = example_conditional_script
        CASE = @example_mod_compat_var
    }
  2. in common/inline_scripts/example_conditional_script:

    inline_script = example_conditional_script_$CASE$
  3. in common/inline_scripts/example_conditional_script_1:

    script (possibly blank) to include if the mod is present
  4. in common/inline_scripts/example_conditional_script_0:

    script (possibly blank) to include if the mod is absent

More complicated logic is also possible:

CASE = @[1-(example_mod_compat_var * example_mod_compat_var_2)]

would implement case 1 of neither of two mods was present and case 0 otherwise, for example.

Some mods use flexible generic conditional scripts which also take a CONTENTS parameter containing the script to implement in case 1;

Scripted Trigger undercoat provides one such set of generic conditional scripts in the stu subfolder.

Clone this wiki locally