Arrays

本页面所适用的版本可能已经过时,最后更新于1.10
白马讨论 | 贡献2021年2月8日 (一) 22:17的版本 (翻译(未完待续))

数组是《钢铁雄心IV》中用以存储变量的方式,变量既可以是数字形式numerical data的,也可以是作用域scope data形式的。

数组在指令effects中发挥作用,并且触发器trigger能够从中读取数据。指令既可以使数组迭代入其他指令,也能使其数据在自身内进行迭代。


指令(Effects)

添加到数组(add_to_array)

add_to_array = {
    array = <name>
    value = <value>
    index = <index>
}

每当有一个变量出现,就会创造一个对应的数组对其进行储存。

<name>是数组的名称,也是指令和触发器调用它的依据。

<value>是指数组的数据内容,它既可以是数字形式的(如1 或 var:my_num),也可以是作用域形式的(如GER 或 var:my_scope)。当然这些都是选填内容,如果不填则会将当前作用域填入此处。

<index>指数据内容应当被插入数组的哪个位置。缺省default data(现普遍称默认)情况下,数据内容会插入数组的最后端,其他情况下新数据内容会自动匹配到合适的位置。

这部分的简便写法是:add_to_array = { <name> = <value> }

从数组中移除(remove_from_array)

remove_from_array = {
	array = <name>
	value = <value>
	index = <index>
}

<name>是想要进行数据内容移除操作的数组名称

<value>是想要移除的数据内容

<index>指移除操作所选择的位置

如果value和index值都未定义或未分配内容,那么最后一个数据内容会被清除

这部分的简便写法是:remove_from_array = { <name> = <value> }


清空数组(clear_array)

clear_array = <name>

清除指定数组中所有数据内容

重置数组规模(resize_array)

resize_array = {
	array = <name>
	value = <value>
	size = <int>
}

重置特定数组规模

如果扩大已经声明过数据内容类型的数组规模,那么多出的位置将以空变量填满,如果没有声明过则缺省值为0。

size属性指定了数组的新大小,如果缩小数组,则删除元素,如果扩大数组,则增加指定值的新元素。

这部分的简便写法是: resize_array = { <name> = <size> }


while_loop_effect

while_loop_effect = {
	break = <string>
	limit = { <triggers> }
	
	<effects>
}

Runs the effect as long as a trigger is true.

The break attribute specifies a temp variable that can be set to non-0 to break the loop, ending iteration. By default this is break.

Effects can be used within the loop to perform operations with the data within an array.

for_each_loop

for_each_loop = {
	array = <name>
	value = <string>
	index = <string>
	break = <string>
	
	<effects>
}

Runs a loop for each element of the specified array.

The value attribute specifies a temp variable that stores the current value whilst iterating over the loop. By default this is v.

The index attribute specifies a temp variable that stores the current index whilst iterating over the loop. By default this is i.

The break attribute specifies a temp variable that can be set to non-0 to break the loop, ending iteration. By default this is break.

Effects can be used within the loop to perform operations with the data within an array.

for_each_scope_loop

for_each_scope_loop = {
	array = <name>
	break = <string>
	
	<effects>
}

Runs a loop for each element of the specified array and changes the current scope to the current element in each iteration.

The break attribute specifies a temp variable that can be set to non-0 to break the loop, ending iteration. By default this is break.

Effects can be used within the loop to perform operations with the data within an array.

random_scope_in_array

random_scope_in_array = {
	array = <name>
	break = <string>
	limit = { <triggers> }
	
	<effects>
}

Runs a loop for each element of the specified array and changes the current scope to a random scope (out of the scopes within the array) that meet the triggers specified.

The break attribute specifies a temp variable that can be set to non-0 to break the loop, ending iteration. By default this is break.

Effects can be used within the loop to perform operations with the data within an array.

add_to_temp_array

Same as add_to_array but for temporary arrays that expire once execution of the script is finished.

remove_from_temp_array

Same as remove_from_array but for temporary arrays that expire once execution of the script is finished.

clear_temp_array

Same as clear_array but for temporary arrays that expire once execution of the script is finished.

resize_temp_array

Same as resize_array but for temporary arrays that expire once execution of the script is finished.

Triggers

is_in_array

is_in_array = {
	array = <name>
	value = <value>
}

Checks if the specified value is in the specified array.

any_of

any_of = {
	array = <name>
	value = <string>
	index = <string>
	
	<triggers>
}

Runs a loop on the specified array and checks the triggers against the current element. If any return true, the whole check returns true, otherwise returns false.

all_of

all_of = {
	array = <name>
	value = <string>
	index = <string>
	
	<triggers>
}

Runs a loop on the specified array and checks the triggers against the current element. If any return false, the whole check returns false, otherwise returns true.

any_of_scopes

any_of_scopes = {
	array = <name>
	
	<triggers>
}

Runs a loop on the specified array and checks the triggers against the current element scope. If any return true, the whole check returns true, otherwise returns false.

all_of_scopes

all_of_scopes = {
	array = <name>
	
	<triggers>
}

Runs a loop on the specified array and checks the triggers against the current element scope. If any return false, the whole check returns false, otherwise returns true.

Additional information

You can set a variable equal to the number of elements in an array by using the following code: set_variable = { var_name = array_name^num } This example will set var_name to be equal to the number of elements in array_name.

Examples