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.
文档 | 效果指令 • 触发条件 • 修正列表 • 作用域 • 变量 • 数据类型 • 本地化 • 可自定义的本地化 |
脚本 | AI • 建筑 • 宣战理由 • 人物 • 人物互动 • 战术 • 国家 • 文化 • 决议 • Defines • 经济政策 • 事件 • 渊源 • 政府 • 总督政策 • 理念 • 修正 • 军事传统 • 官职 • 行动 • 派系 • 价格 • 人口 • 宗教 • 省份 • Script Values • Scripted Modifiers • 附属国类型 • 科技 • 商品 • 特质 • 单位 |
地图 | 地图 • 地形 • 地图定位器 |
图形 | 3D模型 • 界面 • 盾徽 • 图形资产 • 字体 • 粒子效果 • 着色器 • 单位模型 |
音频 | 音乐 • 音效 |
其他 | 控制台命令 • 校验和 • 模组结构 • 错误调试 |