From Stellaris Wiki
Jump to navigation Jump to search


Outliner top.png
This article may contain outdated information that is inaccurate for the current version of the game. It was last updated for 2.2.

This article is for the PC version of Stellaris only.

We can use script-defined variables to perform calculations in scripts and events. Once created, variables are stored in their scope and can be retrieved for later use. Variables can be copied between scopes using the set_variable command (see below), and can be used as part of Bracket Commands in Localisation modding.

Available Scopes[edit]

Currently, we can use variables only within the following scopes: country, fleet, leader, planet , solar_system and galactic_object (star). When a variable is set in a scope, it binds to the scope and persists in it.


set_variable = { which = <string> value = <int/float/variable> } - Sets or creates an named variable within the current scope.

change_variable = { which = <string> = value = <int/float/variable> } - Increments a previously-set variable by a specific amount

subtract_variable = { which = <string> = value = <int/float/variable> } - Decrements a previously-set variable by a specific amount

multiply_variable = { which = <string> = value = <int/float/variable> } - Multiplies a previously-set variable by a specific amount

divide_variable = { which = <string> = value = <int/float/variable> } - Divides a previously-set variable by a specific amount

check_variable = { which = <variable> value = <int/float/variable> } - Checks a variable for the chosen scope - accepts =, >=, >, <=, and < as operators

Copying Variables between Scopes[edit]

We can copy variables between scopes. To do this, the variable must have exactly the same name in the source scope as the destination scope. This command looks for a variable in the "owner" scope called "var1," and if it finds it, copies its value to "var1" in the current scope:

    set_variable = { which = var1 value = owner }

Here is a larger example of the variable being created first in a Country scope, and then later copied to a Planet Scope:

# This = Country
set_variable = { which = var1 value = 123 }
# This = Planet
set_variable = { which = var1 value = owner }
log = "test: [This.var1]" # this will print "test: 123" in the game.log; the [] notations is a Bracket Command; see Localisation modding page for more info

Limitations and Other Notes[edit]

One cannot assign trigger values to a variable. This is a frequently-requested modding feature, but has yet to be implemented by Paradox. For example, the following command will not work:

    set_variable = { which = myvariable value = minerals }

It is not required to "initialize" a variable before use. When a variable is first used, it is assumed by the game to be zero. For example, the following command does nothing useful:

    set_variable = { which = var1 value = 0 }