Wiki

effect · build_railway

Definition

  • Supported scope:any
  • Supported target:any

Description

Builds/adds railway level between two provinces or along a path. Example:
build_railway = {
  level = 1 # Defaults to 1
  build_only_on_allied = yes # No by default. If yes and the effect scope is country, it will only build on allied territories for the country

  # You can specify a weight function that will be used in pathing. The scope will be the controller of the province it is trying to path to.
  # A negative value will make it not to path to that controller.
  # Non-negative values will be used as a path cost for that province.
  controller_priority = {
    base = 1

    modifier = {
      tag = MAN
      add = 2
    }
  }

  # The following options are used for picking a path. You can specify multiple options and it will pick in following order:
  fallback = yes # Default no. If yes, each option will try to fallback to next one.
  # option 1: List of provinces to draw railways. If fallback = yes uses start and end provinces of the path as fallback in option 2.
  path = { 10 20 30 40 }
  # option 2: Specify start & end province IDs. It will pick the shortest path. If provinces are not valid and if fallback = yes it will use states of those provs and use in option 3.
  start_province = 42
  target_province = 84
  # option 3: Specify start & end state IDs. It will pick provinces with the best node (capital > nodes > naval )
  start_state = 50
  target_state = 100
}

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

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

  1. 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."
  2. 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.