Hands-On Usage
has_railway_connection is commonly used in mods to check whether two locations are connected by rail, thereby controlling the availability of certain decisions, technologies, or events—for example, triggering an industrialization event only after rail infrastructure is fully established between the player's core provinces. It can also be applied to AI strategy logic to verify rail connectivity between front lines and rear areas in supply line assessments.
# Example: A decision is available only when a railway connection exists between the capital and target state
available = {
has_railway_connection = {
build_only_on_allied = yes
start_state = 500 # State containing player's capital
target_state = 742 # Target industrial state
}
}
Synergy
[can_build_railway](/wiki/trigger/can_build_railway): Parameters are identical to this trigger. The typical pattern is to first use can_build_railway to check "whether construction is possible," then use has_railway_connection to check "whether it is already built," creating a dual-gate logic for pre-construction and post-construction scenarios.
[build_railway](/wiki/effect/build_railway): When has_railway_connection returns false, trigger build_railway to construct the railway retroactively. The classic pattern is "auto-build if no connection exists."
[has_railway_level](/wiki/trigger/has_railway_level): Using both in combination allows simultaneous constraints on "connection exists" and "connection level meets standard," ideal for high-speed rail or heavy rail mods.
[custom_trigger_tooltip](/wiki/trigger/custom_trigger_tooltip): Wrap has_railway_connection within this to display more readable localized tooltips to players, preventing raw parameter blocks from being exposed directly in the UI.
Common Pitfalls
- Misunderstanding path option priority: The three methods
path, start/target_province, and start/target_state are not equivalent fallback options. The game checks them in a fixed order and only falls back to the next option if the previous one fails when fallback = yes is set. If you write multiple path parameters simultaneously but forget to add fallback = yes, typically only the highest-priority group takes effect, causing the judgment result to diverge from expectations.
- Scope and
build_only_on_allied incompatibility: build_only_on_allied = yes is only meaningful when the scope is a country. Using this parameter under state or province scope will not throw an error, but behavior is undefined, easily causing rail connectivity checks to silently return incorrect results.