Hands-On Usage
build_railway is commonly used in campaign events or upon completion of national focuses to automatically construct railway infrastructure in a specified area, such as simulating "major infrastructure projects" or wartime logistics scenarios. It can also be used in occupation events to selectively build railway networks on allied territory based on the controlling faction's alignment relationships.
# After national focus completion, automatically pathfind and build a level 1 railway between two states, limited to allied territory
complete_national_focus = {
effect = {
build_railway = {
level = 1
build_only_on_allied = yes
fallback = yes
start_state = 42
target_state = 67
controller_priority = {
base = 1
modifier = {
is_ally_with = ROOT
add = 5
}
}
}
}
}
Synergy
[can_build_railway](/wiki/trigger/can_build_railway): Check whether the path is buildable before executing build_railway to avoid silent failures due to unreachable paths.
[has_railway_level](/wiki/trigger/has_railway_level): Used to detect the existing railway level of target provinces/states and combine with if conditions to determine whether an upgrade is needed, preventing duplicate construction.
[has_railway_connection](/wiki/trigger/has_railway_connection): Verify whether a railway connection already exists between two locations, serving as a pre-check or post-check condition for build_railway.
[custom_effect_tooltip](/wiki/effect/custom_effect_tooltip): Since build_railway itself sometimes lacks clear UI feedback, use this command in conjunction to display more explicit construction instructions to the player.
Common Pitfalls
- Mixing
path with start_province/start_state causes logic conflicts: The three pathfinding options have priority ordering. If multiple options are written simultaneously without enabling fallback = yes, the game will only use the highest-priority path field, with all other fields completely ignored. Beginners often mistakenly assume it will "automatically select the optimal solution."
- Using
build_only_on_allied = yes outside country scope is ineffective: This field only functions when the scope is country. If set in a state scope or province scope, it will not error but also will not produce any filtering effect, easily causing bugs where railways are unexpectedly constructed on enemy territory.