Scripted effects

Hstar讨论 | 贡献2020年9月7日 (一) 23:48的版本 (merge from offical wiki)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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.