Triggers

Template:Version

**Conditions** (also known as triggers) are used to specify when the execution of effects occurs. When a trigger returns true, then the execution will continue, otherwise it stops. Multiple triggers can be used together.

## Any Scope

Template:SVersion

Can be used in **country**, **state** or **unit leader** scopes.

## Country Scope

Template:SVersion

Can be used in **country** scope.

## State Scope

Template:SVersion

Can be used in **state** scope.

## Unit Leader Scope

Template:SVersion

Can be used in **unit leader** scope.

### Combat

Template:SVersion

These triggers only work in special unit leader combat scopes, i.e. Combat Tactics.

They should not be used in the regular unit leader scopes.

## Variables

Template:SVersion

Can be used in **country**, **state** or **unit leader** scopes.

```
has_variable = my_var
```
 check\_variable
`value = <float> / <variable>`The value to check for.
`compare = <type>`The type of comparison. Optional, can use < or > instead.
```
check_variable = {
    var = my_var
    value = 10
    compare = greater_than_or_equals
}

```

```
check_variable = {
    my_var > 10
}

```
* less\_than
* less\_than\_or\_equals
* greater\_than
* greater\_than\_or\_equals
* equals
* not\_equals

Remember that variables need to refer to the scope they were set in.

This means you can't check a country variable in a state scope without scoping the variable.

For example, to get the country variable whilst in a state scope, you'd do the following:

```
<country> = {
    <state> = {
        limit = {
            check_variable = { from.my_country_var > 0.0 }
        }
    }
}

```

See Variables for more information.

## Flow Control

Template:SVersion

These scopes alter the evaluation of triggers or introduce effect-like behaviour within a trigger scope.

### Count Triggers

Template:SVersion

Introduced in patch 1.5.

This scope allows a group of triggers to be evaluated multiple times, and if they reach a specified number of passes, then **count\_triggers** returns true.

For example, if you wanted to check if atleast five states out of a group of 10 met their triggers, you'd do the following:

```
count_triggers = {
    amount = 5
    10 = { state_population = 100000 }
    11 = { state_population = 100000 }
    12 = { state_population = 100000 }
    13 = { state_population = 100000 }
    14 = { state_population = 100000 }
    15 = { state_population = 100000 }
    16 = { state_population = 100000 }
    17 = { state_population = 100000 }
    18 = { state_population = 100000 }
    19 = { state_population = 100000 }
    20 = { state_population = 100000 }
}

```

### Hidden Trigger

Template:SVersion

This scope allows triggers to be hidden from the player tooltip. It is useful if you have some messy triggers that may confuse the player. It is useful to use **custom\_trigger\_tooltip** in combination with this.

```
hidden_trigger = {
    country_exists = GER
}

```

### Custom Trigger Tooltip

Template:SVersion

This scope allows a custom tooltip to be displayed for a group of triggers. Here is an example:

```
custom_trigger_tooltip = {
    tooltip = sunrise_invasion_tt
    any_state = {
        is_owned_by = JAP
        is_on_continent = europe
        is_coastal = yes
    }
}

```

## Operators

Template:SVersion

There are two extra operators for triggers, **>** (greater than) and **<** (less than).

They are used for numerical or date triggers, and provide an exclusive check for their value.

This means a trigger using them will return true if the result is any number below (or above).

Note that equals in Hearts of Iron 4 only checks for exact equality, i.e. x = y, whereas in previous games it checks for equals or greater than, i.e. x >= y.

## Context Scopes

Template:SVersion

There are three general scopes all triggers operate in:

* country
* state
* unit leader

They give context to a trigger by stating what the trigger is checking against.

Each country acts as a sub-scope of the general country scope, i.e. `GER = { }` will check only against Germany, whereas `any_country` will check against all countries. Likewise for states and unit leaders.

The important lesson here is that triggers for one type of scope will not work in the other scopes generally (there are exceptions).

## Execution Scopes

Template:SVersion

The use of the following scopes allows for far more flexiblity within triggers.

```
AND = {
    has_war = yes
    has_stability > 0.5
}

 OR
```
OR = {
    is_coastal = yes
    is_capital = yes
}

 NOT
```
NOT = { original_tag = GER }

```

By default in trigger scopes **AND** is applied. Within a **OR** scope, usage of **AND** can be used to restore the behaviour it grants, allowing for very flexible checks.

For example, the following uses this to allow numerous valid states in one check:

```
OR = {
    AND = {
        original_tag = GER
        has_stability > 0.5
    }
    AND = {
        OR = {
            original_tag = ENG
            original_tag = USA
        }
        has_stability > 0.75
    }
    has_stability > 0.9
}

```

In this example, there are three valid states, being Germany with more than 50% stability, being England or USA with more than 75% stability, or being any other country with more than 90% stability.

## References

1. ↑ How does any\_war\_score work?

Template:Modding navbox