执行此代码时,出现错误“尝试调用全局‘forId’(零值)”
function execute(args)
local itemid = 526
local bone = forId(itemid) -- this is where the error occurs
end
function forId(bid)
local xp = 0.0
if bid == 526 or bid == 528 or bid == 2530 or bid == 2859 then
xp = 4.5
elseif bid == 3179 or bid == 3180 or bid == 3183 or bid == 3185 then
xp = 5.0
elseif bid == 530 then
xp = 53
elseif bid == 532 or bid == 3125 then
xp = 15
elseif bid == 4812 then
xp = 22.5
elseif bid == 7839 then
xp = 30
elseif bid == 6812 then
xp = 50
elseif bid == 536 then
xp = 72
end
local bone = Bone:new(bid, xp)
return bone
end
Bone = class(function(b, id, xp)
b.id = id
b.xp = xp
end)
谁能告诉我为什么?
Lua 逐行处理和执行文件,因此定义和使用它们的顺序非常重要。在这种情况下,虽然您似乎没有提供所有代码,因为它看起来像是您正在定义forID
作为全局的,但错误意味着其他情况。您可以简单地尝试更改函数定义的顺序,看看它是否有效。
Bone = class(function(b, id, xp)
b.id = id
b.xp = xp
end)
function forId(bid)
local xp = 0.0
if bid == 526 or bid == 528 or bid == 2530 or bid == 2859 then
xp = 4.5
elseif bid == 3179 or bid == 3180 or bid == 3183 or bid == 3185 then
xp = 5.0
elseif bid == 530 then
xp = 53
elseif bid == 532 or bid == 3125 then
xp = 15
elseif bid == 4812 then
xp = 22.5
elseif bid == 7839 then
xp = 30
elseif bid == 6812 then
xp = 50
elseif bid == 536 then
xp = 72
end
local bone = Bone:new(bid, xp)
return bone
end
function execute(args)
local itemid = 526
local bone = forId(itemid) -- this is where the error occurs
end
但由于您没有提供完整的代码,这可能只会导致错误转移到其他地方。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)