怎么通过这个装备名在local Config = {
["神之一重击Lv.1"] = { col_1 = "神之一重击Lv.1", col_2 = 217, col_3 = 0, col_4 = 1, col_5 = 0, col_6 = 0, col_7 = 0 },
["神之一重击Lv.2"] = { col_1 = "神之一重击Lv.2", col_2 = 217, col_3 = 0, col_4 = 1, col_5 = 0, col_6 = 0, col_7 = 0 },
["神之
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-11 13:15:06 |
👁️ 阅读: 1
根据浮生梦老师前端课程内容,通过装备名在Config表中找到对应位置,可以直接使用装备名作为键来获取配置数据。以下是具体实现方法:
```lua
-- 假设已经获取到装备名
local equipName = "神之一重击Lv.3" -- 这里可以是任意装备名
-- 通过装备名在Config表中查找对应配置
local configData = Config[equipName]
if configData then
-- 找到了对应配置
SL:Print("找到装备配置:")
SL:Print("装备名:", configData.col_1)
SL:Print("col_2值:", configData.col_2)
SL:Print("col_3值:", configData.col_3)
SL:Print("col_4值:", configData.col_4)
SL:Print("col_5值:", configData.col_5)
SL:Print("col_6值:", configData.col_6)
SL:Print("col_7值:", configData.col_7)
-- 可以获取特定字段,比如col_2
local col2Value = configData.col_2
SL:Print("col_2字段值为:", col2Value)
else
SL:Print("未找到装备名对应的配置:", equipName)
end
-- 如果装备名是从装备位获取的,可以这样结合使用:
local equipPos = 0 -- 装备位ID
local nameFromEquipPos = SL:GetMetaValue("EQUIPBYPOS", equipPos)
if nameFromEquipPos and nameFromEquipPos ~= "" then
local equipConfig = Config[nameFromEquipPos]
if equipConfig then
SL:Print("装备位", equipPos, "的装备", nameFromEquipPos, "在Config表中找到配置")
else
SL:Print("装备位", equipPos, "的装备", nameFromEquipPos, "在Config表中未找到配置")
end
end
```
这样就能通过装备名作为键直接访问Config表中的对应配置数据了。
← 返回问答库