【问题标题】:Lua - attempt to call global 'contains' (a nil value)Lua - 尝试调用全局“包含”(零值)
【发布时间】:2013-03-28 20:32:44
【问题描述】:

我很有趣,如果谁知道下面这段代码的问题是什么。我总是收到这个错误:

''尝试调用全局'contains'(一个零值)''

代码如下:

state1={10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,69,72,73,74,85}
state3={78}
state4={1,2,3,4,5,6}

playerskin=initArray2(32,0)
wepskin=initArray2(32,0)

function getPlayerData(id,d)
if (d=="team") then
    if (player(id,"team")==1) then
        return "red"
    end
    if (player(id,"team")==2) then
        return "blu"
    end
end
if (d=="class") then
    return string.lower(tf2.classes.name[tf2.classes.class[id]])
end
end

function changeSkin(id,w)
if (contains(state1,w)) then
    if (playerskin[id]~=0) then
        freeimage(playerskin[id])
    end
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").."   /"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_1.png",1,0,200+id)
end
if (contains(state3,w)) then
    if (playerskin[id]~=0) then
        freeimage(playerskin[id])
    end
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").."/"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_3.png",1,0,200+id)
end
if (contains(state4,w)) then
    if (playerskin[id]~=0) then
        freeimage(playerskin[id])
    end
    playerskin[id]=image("gfx/tf2/skins/"..getPlayerData(id,"team").."/"..getPlayerData(id,"class").."/"..getPlayerData(id,"team").."_"..getPlayerData(id,"class").."_4.png",1,0,200+id)
end
if (hat[id]~=0 and tf2.classes.hatunlock[id][tf2.classes.class[id]]~=0) then
    freeimage(hat[id])
    hat[id]=image(crafts[tf2.classes.hatunlock[id] [tf2.classes.class[id]]].image,1,0,200+id)
end
end

--[[function changeWeaponSkin(id,w)
if (wepskin[id]~=0) then
    freeimage(wepskin[id])
end
wepskin[id]=image("gfx/tf2/skins/weapons/"..getPlayerData(id,"class").." /"..string.lower(tf2.classes.weaponnames[w])..".png",1,0,200+id)
end
]]

addhook("select","tf2.classes.images")
function tf2.classes.images(id,w)
if (player(id,"armor")~=206) then
    changeSkin(id,player(id,"weapontype"))
    --changeWeaponSkin(id,w)
end
end

addhook("spawn","tf2.classes.spawndebug")
function tf2.classes.spawndebug(id)
if (player(id,"armor")~=206) then
    changeSkin(id,player(id,"weapontype"))
    timer(10,"parse","lua changeSkin("..id..",player("..id..",\"weapontype \"))")
    if (tf2.classes.hatunlock[id][tf2.classes.class[id]]~=0) then
        timer(10,"parse","lua freeimage("..hat[id]..")")
        timer(10,"parse","lua   hat["..id.."]=image(crafts[tf2.classes.hatunlock["..id.."][tf2.classes.class["..id.."]]].image,1,0,200+"..id..")")
    else
        timer(10,"parse","lua freeimage("..hat[id]..")")
        timer(10,"parse","lua hat["..id.."]=0")
    end
end
end

addhook("attack2","tf2.classes.spycloak")
function tf2.classes.spycloak(id)
if (tf2.classes.class[id]==9 and player(id,"armor")==0) then
    if (playerskin[id]~=0) then
        freeimage(playerskin[id])
    end
    --[[
    if (wepskin[id]~=0) then
        freeimage(wepskin[id])

如果你有解决方案,请帮助我。

谢谢,

迈克尔

【问题讨论】:

    标签: lua global


    【解决方案1】:

    你有

    if( contains(...) ) then
    

    在您的代码段中。需要定义函数contains 才能调用它。缺少函数定义。

    你可以使用这样的东西(如果你想在表格中找到w):

    function contains( tPassed, iValue )
        for _, v in pairs( tPassed ) do
            if tonumber(v) == tonumber(iValue) then
                return true
            end
        end
        return nil
    end
    

    【讨论】:

    • 感谢 hjpotter92!我在代码之前的第一行中添加了这段代码,它现在可以工作了!再次感谢:)
    猜你喜欢
    • 2013-12-15
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-20
    • 2020-08-02
    • 1970-01-01
    • 2014-11-05
    相关资源
    最近更新 更多