Variables

From Stellaris Wiki
Jump to navigation Jump to search

Version

Outliner top.png
Please help with verifying or updating older sections of this article. At least some were last verified for version 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.

Commands[edit]

Commands on variables have a second parameter, which can be:

  • A literal value: (set|change|subtract|multiply|divide|modulo)_variable = { which = <variable_name> value = <value> }
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
  • A reference which points to another variable in the same scope: (set|change|subtract|multiply|divide|modulo)_variable = { which = <variable_name> which = <another_variable_name> }
  • A scope (in the form of ROOT/FROM/PREV/THIS) which contains a variable with the same name: (set|change|subtract|multiply|divide|modulo)_variable = { which = <variable_name> which = <scope> }

Example[edit]

set_variable = { which = _star_temperature value = @G2V_star_temperature } - Sets a specific star's temperature to the static variable value

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 }
Empire EmpireEthicsGovernments • Civics • OriginsMandatesAgendasTraditions • Ascension PerksEdictsPoliciesRelicsTechnologiesCustom Empires
Pops JobsFactions
Leaders LeadersLeader Traits
Species SpeciesSpecies Traits
Planets PlanetsPlanetary Feature • Orbital DepositBuildings • DistrictsPlanetary Decisions
Systems SystemsStarbasesMegastructuresBypassesMap
Fleets FleetsShips • Components
Land Warfare ArmiesBombardment Stance
Diplomacy Diplomacy • Federations • Galactic CommunityOpinion ModifiersCasus Belli • War Goals
Events EventsAnomaliesSpecial projectsArchaeological Sites
Gameplay GameplayDefinesResources • Economy
Dynamic modding EffectsConditionsScopesModifiersVariablesAI
Media/localisation Maya exporterGraphicsPortraitsFlagsEvent picturesInterfaceIconsMusicLocalisation
Other Console commandsSave-game editingSteam Workshop