-
-
Notifications
You must be signed in to change notification settings - Fork 0
Variables
- 1. Wiki Section: https://stellaris.paradoxwikis.com/Variables
- 2. From
common/scripted_variables/00_scripted_variables.txt -
3. From
events/000_how_to_use_variables_in_script.txt - [4. From (Discord > Stellaris Modding Den > This Post)](#4-from-discord--stellaris-modding-denhttpsdiscordggcujjaqzutt--this-posthttpsdiscordcomchannels3789859493733990401385448934910201946)
This Wiki page was last updated for v4.4.*
1. Wiki Section: https://stellaris.paradoxwikis.com/Variables
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.
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)
- 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_valuesviavalue: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.
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
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)
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
whileloops! - 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 onadd_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.
See Discord > Stellaris Modding Den > This Post)
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):
-
in your Target file to use Conditional Code:
inline script = { script = example_conditional_script CASE = @example_mod_compat_var }
-
in
common/inline_scripts/example_conditional_script:inline_script = example_conditional_script_$CASE$
-
in
common/inline_scripts/example_conditional_script_1:script (possibly blank) to include if the mod is present
-
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.
Note
This is a Markdown file and is formatted for viewing in
You can read the Markdown Wiki to learn how to use and modify these types of files.
This Documentation is for