钢铁雄心(Hoi4)数组 Array 简单应用
钢铁雄心4中Array可以实现一些内容的数组化,例如将一些国家id存在一个清单中,供我们要做的功能进行对接,几个例子,在kr的各个经济圈,tno的经济圈中应用了大量的array数组功能,而数组array与变量variable紧密相连。结合本人做mod的经验我们接下来介绍几个简单的例子
通常为了方便与整洁,以及适合调用,我"推荐"可以将变量,数组等编写的内容放进Scripted_effect(脚本 效果)文件夹中的新建文件去编写,文件名称可以注明相应的效果内容帮助分类
1.Scrpted_effect文件内部格式
xxxxxxx(接口名称)= {
<effect> #例如 add_stability = 0.05
}
在国策,决议,事件或者其他脚本效果调用时,只需要声明
remove_effect = {
xxxxxxx = yes
}
就可以调用相关效果,例如增加5%稳定度
2.数组Array与变量variable的应用
数组的操作 添加数组
模板 add_to_array = {
array = country_list_0 #数组名称,如果数组不存在视为创建一个新数组
value = <value> #数值,就是在列表相应位置的值
index = <index> #位置,默认以0为开头
}
以下的函数帮助我们将与德国作战的国家加入列表,从0开始,以此加1
set_variable = { i0 = 0 }
every_country = {
limit = {
has_war_with = GER
}
add_to_array = {
array = country_war_germany_array
value = this
index = i0
}
add_to_variable = { i0 = 1 }
}
这个country_war_germany_array数组里将存储所有与德国开战的国家
这里要注意,如果我们想要在已有的list(array)上刷新数组的话,通常我们必须指定index,也就是位置是从0开始,然后使用变量的加法进行递增,否则变量将被添加到列表的末尾。
一些操作:::
(1)在数组中移除一个变量值
当我们在一个数组中要移除一个变量value值,例如一个经济圈中,将一个国家移除,这个时候可以使用 remove_from_array 进行移除,作用是从一个数组移除一个变量或一个相应位置(index)的变量
1.remove_from_array = {
array = sphere_econ
value = GER
}
2.remove_from_array = { sphere_econ = GER }
以上操作将会把ger国家移除出sphere_econ数组
remove_from_array = {
array = sphere_econ
index = 1
}
以上操作会把数组sphere_econ在1位置的国家(value)移除
(2)清除一个数组
如果我们在使用过程中需要删除这个数组,例如将一个经济圈数组移除,可以使用clear_array
clear_array = sphere_econ
以上操作将移除sphere_econ数组里的所有内容
(3)得到数组中存储元素的数量
如果我们想要获取在数组中的元素数量,例如我们创建了一个经济圈的数组,需要获取到经济圈中成员数量
模板:set_temp_variable = { var_name = array_name^num }
set_temp_variable = { member_num_sphere = sphere_econ^num }
set_variable = { member_num_sphere = sphere_econ^num }
member_num_sphere变量中(暂时)存储了经济圈中成员数量
(4)在变量中引用特定数组相应index位置的变量值
如果我们想在数组中获取相应位置的变量值(value)给变量(variable)进行相应操作时,可以使用以下方法
模板:set_temp_variable = { var_name = array_name^index }
set_temp_variable = { member_name_sphere= sphere_econ^3 }
set_variable = { member_name_sphere = sphere_econ^3 }
以上操作通过固定位置获得sphere_econ数组中第3个index存储的value值,例如是GER,并存储在member_name_sphere变量中供操作
(5)指定一个数组array的大小
我们可以通过指定一个数组的大小来扩大,缩小其元素value的范围
resize_array = {
array = sphere_econ
value = 3
size = 5
}
resize_array = { array_name = size }
以上操作的含义是将sphere_econ数组内大小变为5,value视为填充的值,如果未设置value时,统一视为0,当array(sphere_econ)的元素个数小于5时,填充部分的value将为3,size为设置数组长度,实行多删少补
临时数组(temp_array)版本以 resize_temp_array 的形式存在。
(6)获取在数组中最高和最低的value或代表的index
这个是用于一个数组array里的value值(变量值)均为数字,包括整数和浮点数时,可以通过find_highest_in_array和find_lowest_in_array获取数组中最高或最低的value值或者value值代表的元素位置index
1.获取数组中最高value值
find_highest_in_array = { array = array_name value = value_name index = index_name}
使用方法(很明显,改数组操作不支持内置effect)
find_highest_in_array = {
array = num_array_list
value = num_array_max_num #该num_array_max_num 变量存储数组value最大值
index = num_array_max_num_index #num_array_max_num_index存储最大值的index
2.获取数组中最小value值
find_lowest_in_array = { array = array_name value = value_name index = index_name}
使用方法(很明显,改数组操作不支持内置effect)
find_lowest_in_array = {
array = num_array_list
value = num_array_min_num #该num_array_min_num 变量存储数组value最小值
index = num_array_min_num_index #num_array_min_num_index存储最小值的index
}
(7)对符合限制条件进行迭代循环
当我们需要设置符合我们设置limit条件的内容进行循环操作时,可以使用while_loop_effect
模板1:此操作可以视为变量(variable)操作
while_loop_effect = {
break = <string>
limit = {
<triggers>
}
<effects>
}
break设置为中断循环,默认为break ,即不中断循环,可以设置一个非0的数值可以在适当位置进行中断,一般不需要设定,可以视为迭代循环的次数,对数组的操作唯一不同的就是最大限制条件变为数组范围内。
limit为限制条件
effect为符合limit后所进行的操作
例如:
1.
while_loop_effect = {
break = 5 #设置迭代次数为5
limit = {
GER = { has_war = no }
}
GER = { add_stability = 0.10 }
}
2.
set_temp_variable = { while_loop_temp_name = 0 } #设置临时次数0
while_loop_effect = {
limit = {
GER = { has_war = no }
check_variable = { while_loop_temp_name < 6 } #设置迭代次数为5(小于6)
}
GER = { add_stability = 0.10 }
add_to_temp_variable = { while_loop_temp_name = 1 } #临时次数+1
}
著名:上面都已整数1为最小迭代次数,浮点数迭代次数例如0.1,5.0请自行操作
通过以上1.2种方法可以实现有次数限制的迭代效果管理
(8)对数组中所有元素进行循环并操作
当我们需要将数组里的所有元素或者value进行循环并操作时,我们可使用for_each_loop
模板:
for_each_loop = {
array = <name>
value = <string>
index = <string>
break = <string>
<effects>
}
1.例子:我想实现让所有经济圈内成员加一个变量值,并将这些成员加载到一个新的数组中
set_temp_variable = { clo_member_num = 0 }
for_each_loop = {
array = econ_sphere #含有美国,德国,英国,法国,意大利,每个都可以轮到
set_temp_variable = { econ_sphere_temp_member = v } #获取列表当前元素国家
econ_sphere_temp_member = {
set_variable = { member_policital_num = 100 } #元素国家设置变量
}
add_to_array = { #载入到一个新的数组
array = econ_sphere_new
value = econ_sphere_temp_member
index = clo_member_num
}
add_to_variable = { clo_member_num = 1 }
set_variable = { econ_spherer_new_num = econ_sphere_new^num }#新经济圈国家数量
}
(9)对数组内的元素进行循环并操作
改逻辑与第8个效果大致相同,不同的是for_each_scope_loop 在每次迭代中将当前范围更改为当前元素,该循环也没有limit,但可以使用break次数中断循环
将此临时变量设置为非零以中断循环 = loc #如果已定义,效果将使用此本地化作为标题输出子效果的工具提示 #effect 1 #effect 2 ... }
模板
for_each_scope_loop = {
array = <name>
break = <string>
<effects>
}
1.使用例
for_each_scope_loop = {
array = num_array #数组,1,1,2,3,4,5
break = 1 #循环1
add_to_variable = { v = 1 }
}
