调用方式
Functions.collections.index(array, value)
将其记录为名为 Functions.collections.index 的依赖项(接受自动补全即可完成),然后按该名称调用。
作用
在 pairs 遍历过程中返回第一个值等于所提供值的键。输入表为 nil 或 false 以及值不存在时返回 nil。有多个匹配的键时,选择顺序不确定。
参数
| 名称 | 类型 | 作用 |
|---|---|---|
array | table | nil | false | 要搜索的表;为 nil 或 false 时返回 nil。 |
value | any | 使用 Lua 相等比较与表中每个值进行比较的值。 |
返回值
| 1 | any | 匹配的键(包括 false 键);不存在匹配时为 nil。 |
|---|
版本
内置辅助函数在每个版本上都会注册。不同的是它们读取的游戏 API;某个 API 缺失时,辅助函数会改用后备方案,或返回 nil 并附上原因。
它不直接读取任何游戏 API。
示例
local priority = { "Fire", "Frost", "Arcane" }
local slot = Functions.collections.index(priority, "Frost")
return slot ~= nil and slot <= 2源码
Functions/collections.lua,第 76 行。在游戏中为只读;“复制”会生成一份可编辑的副本。
Functions.collections.index(array, value)
if not array then return nil end
for idx,v in pairs(array) do
if (v == value) then
return idx
end
end