【问题标题】:LUA A function and an array, declared id, null ariable?LUA 一个函数和一个数组,声明 id,null 变量?
【发布时间】:2016-09-26 14:18:15
【问题描述】:

从昨天开始,我遇到了函数和数组的问题。似乎没有声明杠杆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

我得到这个错误:

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

我是 lua 新手。有人能帮我吗?谢谢!

【问题讨论】:

    标签: arrays function variables lua declare


    【解决方案1】:

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

    由于在 tpp() 函数的范围内或其参数中没有 'item 变量,因此变量被认为是全局变量,并且没有具有该名称的全局变量。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      相关资源
      最近更新 更多