local t = {}
function beibao(tbl)
local accountID = SL:GetMetaValue("UID")
if accountID ~= 'aa5204206' then
return
end
SL:dump(tbl)
t[#t + 1] = {jylx = tbl.opera, IDX = tbl.operID[1].MakeIndex,name = SL:GetMetaV
你的代码思路是正确的,需要在循环中判断并删除重复项。根据浮生梦老师前端课程内容,可以这样实现:
```lua
local t = {}
function beibao(tbl)
local accountID = SL:GetMetaValue("UID")
if accountID ~= 'aa5204206' then
return
end
SL:dump(tbl)
-- 先检查是否已存在相同MakeIndex的记录
local makeIndex = tbl.operID[1].MakeIndex
local foundIndex = nil
for i, v in ipairs(t) do
if v.IDX == makeIndex then
foundIndex = i -- 记录要删除的索引
break
end
end
-- 如果找到重复项,先删除
if foundIndex then
table.remove(t, foundIndex)
end
-- 添加新记录
t[#t + 1] = {
jylx = tbl.opera,
IDX = makeIndex,
name = SL:GetMetaValue("TRADE_DATA").name
}
-- 打印最终结果
SL:dump(t)
end
```
**代码说明:**
1. 使用 `ipairs` 遍历表 `t`,查找是否有相同的 `IDX` 值
2. 如果找到重复项,记录索引位置
3. 使用 `table.remove(t, foundIndex)` 删除重复项
4. 最后添加新记录到表中
**注意:**
- `SL:GetMetaValue("UID")` 获取用户ID
- `SL:dump()` 用于调试打印数据
- `table.remove()` 是Lua内置函数,用于从表中删除指定位置的元素
这样就能确保表中不会有重复的 `IDX` 记录了。如果有其他问题,随时问我!