Wiki

trigger · has_trait

Definition

  • Supported scope:CHARACTER, COMBATANT
  • Supported target:none

Description

check if sides leader has trait

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

has_trait is commonly used to check whether a character or leader possesses a specific trait, enabling conditional logic for subsequent events or unlocking special options. For example, you can verify prerequisite traits in leader growth events or filter characters with certain traits in advisor recruitment conditions. The following example demonstrates how to restrict an event option to characters that hold a specific trait:

# Used within event trigger conditions or option available blocks
available = {
    FROM = {
        has_trait = guerrilla_fighter
    }
}

Synergy

  • [can_select_trait](/wiki/trigger/can_select_trait): Use has_trait first to confirm the current trait ownership status, then use can_select_trait to determine if a target trait can be unlocked. Together, they construct prerequisite checking logic for trait trees.
  • [add_trait](/wiki/effect/add_trait): After condition checks pass, execute add_trait to implement a safe "add if not already owned" pattern, preventing unintended trait stacking.
  • [replace_unit_leader_trait](/wiki/effect/replace_unit_leader_trait): Combine with has_trait to confirm the old trait exists before replacing it, preventing script errors or silent failures caused by missing traits.
  • [add_timed_unit_leader_trait](/wiki/effect/add_timed_unit_leader_trait): Pair with has_trait to implement advanced logic such as "stack temporary trait enhancements only when a permanent trait is present".

Common Pitfalls

  1. Scope Confusion: has_trait requires the scope to be CHARACTER or COMBATANT. Beginners often call it directly under COUNTRY scope without switching scopes (e.g., forgetting to use any_character/FROM to enter character scope), causing the condition to never evaluate true and producing no obvious error message from the engine.
  2. Trait Name Spelling Depends on Internal Key: The trait identifier passed must be the trait key defined internally in the game (e.g., old_guard), not the localized display name. Using Chinese text or display names directly will cause the condition to silently fail, making it difficult to debug.