Arrays 一个函数和一个数组,声明id,空变量?

Arrays 一个函数和一个数组,声明id,空变量?,arrays,function,variables,lua,declare,Arrays,Function,Variables,Lua,Declare,从昨天开始,我对函数和数组有一个问题。似乎杠杆ID没有声明或其他什么 这是我的密码: function tpp(leverID, from, to) if item.uid == leverID and item.itemid == 1945 then local count_players = #to local store = {} for i = 1, count_players do local pid = getTopCreature(fr

从昨天开始,我对函数和数组有一个问题。似乎杠杆ID没有声明或其他什么

这是我的密码:

function tpp(leverID, from, to)

if item.uid == leverID and item.itemid == 1945 then

    local count_players = #to
    local store = {}

    for i = 1, count_players do
        local pid = getTopCreature(from[i]).uid
        if (pid == 0 or not isPlayer(pid)) then
                return doPlayerSendCancel(cid, 'You need ' .. count_players .. ' players to use this lever.')
        end
        store[i] = pid
    end

    for i = 1, count_players do
        doSendMagicEffect(from[i], CONST_ME_POFF)
        doTeleportThing(store[i], to[i], false)
        doSendMagicEffect(to[i], CONST_ME_TELEPORT)
    end

    doTransformItem(item.uid, item.itemid + 1)

elseif item.uid == leverID and item.itemid == 1946 then
    doTransformItem(item.uid, item.itemid -1)
end

end




function onUse(cid, item, fromPosition, itemEx, toPosition)


local pos = {
    ['pos_start'] = {
            {['x'] = 1059, ['y'] = 1034, ['z'] = 7},
            {['x'] = 1060, ['y'] = 1034, ['z'] = 7}
    },
    ['pos_end'] = {
            {['x'] = 1059, ['y'] = 1032, ['z'] = 7},
            {['x'] = 1060, ['y'] = 1032, ['z'] = 7}
    }
}

tpp(10150, pos['pos_start'], pos['pos_end'])

return true


end
我得到了这个错误的答案:

尝试索引全局“项”(零值)


我是卢阿的新手。有人能帮我吗?谢谢

当您从onUse()函数调用时,可能忘记了将'item'变量传递给tpp()函数

由于tpp()函数的作用域或其参数中并没有“item”变量,所以该变量被认为是全局变量,并且并没有具有该名称的全局变量