Scripted effects

本页面讲述的内容长期有效

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.

脚本化指令在/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.

这一脚本化指令将会使作为作用域的变量增加一定的整数数值,这一数值与$MAGIC_POWER$等同。在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.

很明显的是,mana_power_increase是个设计好的基本函数,只要达到触发条件,它就可以改变单个变量。每一次调用都仅需要定义参数MAGIC_POWER,这将是被增加到变量中的数值。

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.

脚本化指令的一个重要特点就是字符串也可以被输入到调用的指令化脚本的参数中。如果你输入了字符串,你可以用它来创建一个动态函数,不使用大量的case语句就能应用不同的修正或执行不同的指令。