function chakanbeibao(actor,id,obj)
local bagItems = getbagitems(obj)
local beibaoname = {}
local beibaonum = {}
local weiyi= {}
for k, v in ipairs(bagItems) do
beibaoname[k] = getiteminfo(actor,v,7)
beibaonum[k]
我是Lua后端老师!修仙者,我来帮你分析一下这段代码的问题。
问题出在第16行,你使用了 `wode[i]` 这个变量,但实际上在前面循环中你存储唯一ID的变量名是 `weiyi`,而不是 `wode`。
```lua
function chakanbeibao(actor,id,obj)
local bagItems = getbagitems(obj)
local beibaoname = {}
local beibaonum = {}
local weiyi = {} -- 这里定义了weiyi数组
for k, v in ipairs(bagItems) do
beibaoname[k] = getiteminfo(actor,v,7) -- 获取物品名称
beibaonum[k] = getiteminfo(actor,v,5) -- 获取叠加数量
weiyi[k] = getiteminfo(obj,v,1) -- 获取唯一ID,存储到weiyi数组
end
local x = 0
local y = 0
local children = ''
local itemshow = ''
local itembg = ''
for i=1 ,#beibaoname do
children = children .. 'v'..i..','
children = children .. 'l'..i..','
if x > 539 then
x = 0
y = y + 70
end
itembg = itembg .. '<Img|id=v'..i..'|x='..x..'|y='..y..'|img=public/1900000651_3.png>'
-- 这里应该使用weiyi[i],而不是wode[i]
itemshow = itemshow .. '<DBItemShow|id=l'..i..'|x='..x..'|y='..y..'|makeindex='..weiyi[i]..'|link=@跳转触发>'
x = x + 69
end
local str = [[
<ListView|children=ggg|x=122.0|y=1.0|width=576|height=409>
<Layout|id=ggg|children=]]..children..[[|x=152.0|y=1.0|width=576|height=999>
<Button|x=619.0|y=432.0|color=255|nimg=public/btn_npcfh_01.png|size=18|link=@chaxunwanjia>
]]
str = str .. itembg..itemshow
main(actor,id,str)
end
```
修正后的代码将第16行的 `wode[i]` 改为 `weiyi[i]`,这样就能正确显示物品的唯一ID了。下次写代码要仔细检查变量名哦,不懂的可以问浮生梦尊师!