Wiki

trigger · check_variable

Definition

  • Supported scope:any
  • Supported target:any

Description

Compares a variable to a number or another variable
ex:
check_variable = {
	var = varname
	value = 12	# accepts variables
	compare = equals
	# possible values for compare :
	# less_than, less_than_or_equals
	# greater_than, greater_than_or_equals
	# equals, not_equals
	tooltip = loc_str_id_with_LEFT_and_RIGHT  #localized text with LEFT and/or RIGHT tokens in it
}
# some shorter versions :
check_variable = { varname = 0 }
check_variable = { varname > 12 }
check_variable = { varname < 42 }
check_variable = { varname > another_varname }

Hands-On Notes

Hands-on notes are AI-generated and checked against the vanilla command vocabulary — treat them as a starting point, not authoritative reference. The definition above is the game's own documentation.

Hands-On Usage

check_variable is most commonly used in scenarios involving tracking player-defined counters, resource variables, or progression stages—for example, determining whether an event chain has triggered a sufficient number of times, or verifying whether accumulated "prestige points" set via set_variable are enough to unlock a particular decision. The example below checks whether a country's "influence points" variable is greater than or equal to 50 before allowing a decision to trigger:

available = {
    check_variable = {
        var = my_mod_influence_points
        value = 50
        compare = greater_than_or_equals
    }
}

Synergy

  • [has_variable](/wiki/trigger/has_variable): Check whether a variable has been initialized before using check_variable to avoid errors caused by missing variables.
  • [set_variable](/wiki/effect/set_variable): Typically use set_variable in an effect block to write or reset variable values, then read and compare them in subsequent triggers using check_variable, forming a complete "write-read" cycle.
  • [add_to_variable](/wiki/effect/add_to_variable): After performing cumulative operations on a variable, pair it with check_variable to detect whether a trigger condition has been met; this is the standard pattern for counter-based designs.
  • [if](/wiki/trigger/if): Embed check_variable within if statements in complex conditional blocks to branch logic based on variable values.

Common Pitfalls

  1. Comparing variables without initialization: If the target variable has never been assigned a value via set_variable or add_to_variable, check_variable will read it as 0, but in certain contexts this may silently fail or produce unexpected results. Always set default values in initialization events or on_startup and protect with has_variable checks.
  2. Writing comparison operators as assignment syntax: Beginners often confuse compare = equals with assignment syntax in effect blocks, or mistakenly use = in shorthand forms to mean "equals comparison" (the correct shorthand for equality is { varname = 0 }), leading to logic that doesn't match intentions. Pay careful attention to the equivalence between shorthand and full forms.