Scripted effects are a way of reducing necessary code duplication. They work like a macro, and can take particular values to help significantly reduce the amount of code that must be created.
Scripted effects are defined in /Crusader Kings III/common/scripted_effects.
Below is an example of a scripted effect:
mana_power_increase = { if = { limit = { NOT = { exists = var magic_power } } set_variable = { name = magic_power value = 0 } } change_variable = { name = magic_power add = $MAGIC_POWER$ } }
This scripted effect will increase a variable in a scope by the integer value that corresponds to $MAGIC_POWER$. This effect is invoked by the following example found in a lifestyle_perk.
mana_power_increase = { MAGIC_POWER = 5 }
As should be pretty clear, mana_power_increase is a basic function designed to change a single variable so long as the trigger conditions are met. Each invocation merely requires defining the value MAGIC_POWER which will be the value that is added to the variable.
An important feature of scripted effects are that the values that can be passed to the scripted effect from the invocation are string values. If you pass a string, you can use this to create a dynamic function that will apply different modifiers or execute different effects without using large case statements.
文档 | Effects • 触发器 • 修正 • 作用域 • 变量 • 数据类型 • 本地化 • 可定制的本地化 |
脚本 | AI • 剧本 • 角色 • 效果指令 • 内阁 • 文化 • 决议 • 宗族 • 事件 • 政体 • 历史 • 地产 • 生活方式 • 军队 • 宗教 • Story cycles • 头衔 • 特质 |
地图 | 地图 • 地形 |
图形 | 3D模型 • Exporters • 界面 • Coat of arms • Graphical assets • Fonts • Particles • Shaders • Unit models |
音频 | Music • Sound |
其他 | 控制台指令 • 校验码 • 模组结构 • Troubleshooting |