Script Values

本页面讲述的内容长期有效
自由之民讨论 | 贡献2022年5月31日 (二) 20:19的版本 (2021年5月11日 (二) 16:14‎ DC123456789)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)


Script values are functions that calculate a value, based on a number of conditions.

Script values are not stored anywhere, they are temporary and exist only when a script calls them. However, they can be displayed in UI, which seems to calculates them on every frame.

They are placed in common/script_values, in a .txt file.

A basic script value (also "svalue"), looks like this:

my_value = {
  value = country_population
  multiply = 10
  add = 20
}

To use an svalue in a script, simply write its name, like this add_treasury = my_value

The scope of an svalue depends on where from script it is called. If you are in a country scope, the svalue will also be in a country scope, meaning it will expect country triggers and effects. The svalue above cannot be called for a territory or character, for example.

Svalue accepts effects, and a function like add can be used inside them to change the svalue.

Important: make sure you are using an effect and not a trigger for this. Every_ or random_ functions are effects, while any_ is a trigger. Example:

cities_in_state = {
  value = 0
  every_state_province = {
    limit = { has_province_rank = city }
    add = 1
  }
}

We can have multipe effects and if statements:

slaves_needed = {
  value = 20

  if = {
    limit = { has_city_status = no }
    add = -5
  }

  if = {
    limit = { terrain = farmland }
    add = -2
  }
}

Script values can call each other. They can use values from variables (with var:variable_name) and variables can be set to them, to save a value permanently.

Changes to script values reload instantly if you started the game in debug_mode, but some triggers may break after a reload, like terrain or pop_type. Restart the game if a script value doesn't seem to work properly while its syntax looks to be correct.