数组:修订间差异
小 (→专用用法) 标签:移动版编辑 移动版网页编辑 高级移动版编辑 |
小无编辑摘要 |
||
| (未显示2个用户的25个中间版本) | |||
| 第6行: | 第6行: | ||
{| class="wikitable" | {| class="wikitable" | ||
|+数组支持的类型 | |+数组支持的类型 | ||
|boolean | |boolean[] | ||
|布尔值 | |布尔值 | ||
|- | |- | ||
|float | |float[] | ||
|浮点数 | |浮点数 | ||
|- | |- | ||
|number | |number[] | ||
|整数 | |整数(float) | ||
|- | |- | ||
|unit | |unit[] | ||
|单位 | |单位 | ||
|} | |} | ||
| 第28行: | 第28行: | ||
@memory是defineUnitMemory的快捷方式,通常由多行多个@memory组成。 | @memory是defineUnitMemory的快捷方式,通常由多行多个@memory组成。 | ||
单个@memory的格式为: <code>@memory 名称:类型 | 单个@memory的格式为: <code>@memory 名称:类型</code> | ||
{{折叠|@memory的例子|<pre> | {{折叠|@memory的例子|<pre> | ||
@memory dir:float[] | @memory dir:float[] | ||
| 第45行: | 第45行: | ||
===跨单位引用=== | ===跨单位引用=== | ||
要引用其他单位的内存,可以使用<code>readUnitMemory</code> | 要引用其他单位的内存,可以使用<code>readUnitMemory</code> | ||
''' | <code>单位引用.readUnitMemory('名称',type='类型',index='下标')</code> | ||
self.customTarget1.readUnitMemory('a',type='number',index=114) | <code>self.customTarget1.readUnitMemory('a',type='number',index=114)</code> | ||
</ | |||
== | === 修改数组 === | ||
在[action]中,可以通过<code>setUnitMemory</code>来直接修改内存的值,格式为<code>setUnitMemory:名称[下标]=值</code> 。 | 在[action]中,可以通过<code>setUnitMemory</code>来直接修改内存的值,格式为<code>setUnitMemory:名称[下标]=值</code> 。 | ||
| 第61行: | 第60行: | ||
</pre>}} | </pre>}} | ||
和内存一样,数组也可以通过<code>[core]updateUnitMemory</code>来更新。 | 和内存一样,数组也可以通过<code>[core]updateUnitMemory</code>来更新。 | ||
==跨单位读数组== | |||
readUnitMemory('名称',type='类型')['下标'] | |||
readUnitMemory('名称',type='类型')[('数学运算下标')] | |||
readUnitMemory('名称',type='类型').get('下标') | |||
警告:截止1.15版,跨单位读数组,由于游戏bug,单位参考将被重定向。 | |||
<pre> | |||
代码: | |||
customTarget1.readUnitMemory("obj",type="unit[]").get(memory.index) | |||
customTarget1.readUnitMemory("obj",type="unit[]").get(self.hp) | |||
customTarget1.readUnitMemory("obj",type="unit[]").get(memory.unit.readUnitMemory("index",type="float")) | |||
实际运行结果:(伪代码) | |||
customTarget1.memory.obj.get(customTarget1.memory.index) | |||
customTarget1.memory.obj.get(customTarget1.hp) | |||
customTarget1.memory.obj.get(customTarget1.memory.unit.memory.index) | |||
</pre> | |||
局部函数不受此影响。 | |||
如:thisActionIndex/index,eventSource,thisActionTarget。 | |||
使用消息接受数组,将返回空数组。 | |||
eventData("get",type="float[]")=[] | |||
{{折叠|复制数组|<pre> | |||
[hiddenAction_copy] | |||
alsoTriggerAction:set | |||
alsoTriggerActionRepeat:customTarget1.readUnitMemory("obj",type="unit[]").size | |||
alsoTriggerOrQueueActionWithTarget:customTarget1 | |||
[hiddenAction_set] | |||
setUnitMemory:buffer[index]=thisActionTarget.readUnitMemory("obj",type="unit[]").get(index)</pre> | |||
}} | |||
===重定向到自己=== | |||
使用局部变量重定向到自己。 | |||
<pre> | |||
[hiddenAction_0] | |||
alsoTriggerAction:1 | |||
alsoTriggerOrQueueActionWithTarget:self | |||
[hiddenAction_1] | |||
debugMessage:customTarget1.readUnitMemory("arr",type="float[]").get(thisActionTarget.readUnitMemory("index",type="float")) | |||
</pre> | |||
===修改值=== | |||
使用发信等方式修改目标的值,通过被重定向目标进行访问(这里不提供代码实现) | |||
== 专用用法 == | == 专用用法 == | ||
* <code>数组名.size</code> 返回数组大小(元素个数) | * <code>数组名.size/数组名.length</code> 返回数组大小(元素个数) | ||
* <code>数组名=null</code> 清空数组,大小变为0 | * <code>数组名=null</code> 清空数组,大小变为0 | ||
* <code>数组名.contains("数据")</code> 检测数组中是否包含这个数据 | * <code>数组名.contains("数据")</code> 检测数组中是否包含这个数据 | ||
2024年2月27日 (二) 18:57的最新版本
数组(array)是铁锈1.15p11加入的一种数据结构。
数组可以存储多个同种类型的元素,在铁锈中,数组存储数量最大值为10000。
支持的类型
| boolean[] | 布尔值 |
| float[] | 浮点数 |
| number[] | 整数(float) |
| unit[] | 单位 |
定义
与普通内存一样,在[core]节中,可以使用defineUnitMemory和@memory来定义数组,数组名字可以包含中文。
通过defineUnitMemory定义
在[core]节中添加: defineUnitMemory:类型 名称[]
通过@memory定义
@memory是defineUnitMemory的快捷方式,通常由多行多个@memory组成。
单个@memory的格式为: @memory 名称:类型
| @memory的例子 |
|---|
@memory dir:float[] @memory amo:number[] @memory armor_f:unit[] |
引用
下标
下标是一个整数,用来索引数组的特定项。在铁锈中,数组下标从0开始。
单位内部引用
要引用单位内部的自定义内存,可以直接使用 memory.名称[下标] 。
跨单位引用
要引用其他单位的内存,可以使用readUnitMemory
单位引用.readUnitMemory('名称',type='类型',index='下标')
self.customTarget1.readUnitMemory('a',type='number',index=114)
修改数组
在[action]中,可以通过setUnitMemory来直接修改内存的值,格式为setUnitMemory:名称[下标]=值 。
当修改的下标在数组中不存在时,数组大小将会更改为修改的下标。
| setUnitMemory例子 |
|---|
# [action] 中 setUnitMemory:a[1]=1,b=memory.b[memory.a[1]]+1 |
和内存一样,数组也可以通过[core]updateUnitMemory来更新。
跨单位读数组
readUnitMemory('名称',type='类型')['下标']
readUnitMemory('名称',type='类型')[('数学运算下标')]
readUnitMemory('名称',type='类型').get('下标')
警告:截止1.15版,跨单位读数组,由于游戏bug,单位参考将被重定向。
代码:
customTarget1.readUnitMemory("obj",type="unit[]").get(memory.index)
customTarget1.readUnitMemory("obj",type="unit[]").get(self.hp)
customTarget1.readUnitMemory("obj",type="unit[]").get(memory.unit.readUnitMemory("index",type="float"))
实际运行结果:(伪代码)
customTarget1.memory.obj.get(customTarget1.memory.index)
customTarget1.memory.obj.get(customTarget1.hp)
customTarget1.memory.obj.get(customTarget1.memory.unit.memory.index)
局部函数不受此影响。 如:thisActionIndex/index,eventSource,thisActionTarget。
使用消息接受数组,将返回空数组。
eventData("get",type="float[]")=[]
| 复制数组 |
|---|
[hiddenAction_copy]
alsoTriggerAction:set
alsoTriggerActionRepeat:customTarget1.readUnitMemory("obj",type="unit[]").size
alsoTriggerOrQueueActionWithTarget:customTarget1
[hiddenAction_set]
setUnitMemory:buffer[index]=thisActionTarget.readUnitMemory("obj",type="unit[]").get(index)
|
重定向到自己
使用局部变量重定向到自己。
[hiddenAction_0]
alsoTriggerAction:1
alsoTriggerOrQueueActionWithTarget:self
[hiddenAction_1]
debugMessage:customTarget1.readUnitMemory("arr",type="float[]").get(thisActionTarget.readUnitMemory("index",type="float"))
修改值
使用发信等方式修改目标的值,通过被重定向目标进行访问(这里不提供代码实现)
专用用法
数组名.size/数组名.length返回数组大小(元素个数)数组名=null清空数组,大小变为0数组名.contains("数据")检测数组中是否包含这个数据[action]shrinkArrays移除数组中空的部分
| shrinkArrays例子 |
|---|
|
array a=1,2,0,3
|