2016-05-28 3 views
2

私は昨日から関数と配列に問題があります。LUA関数と配列、宣言されたid、null ariable?

attempt to index global 'item' (a nil value)

私はLUAに新しいです:私はこのエラーを取得する

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 

:ここで

は私のコードです...そのレバーのIDが宣言か何かされていないようです。誰か助けてくれますか?ありがとう!

答えて

1

おそらく、 'item'変数をonUse()関数から呼び出したときに、tpp()関数に渡すのを忘れていました。

tpp()関数の範囲またはその引数にitem変数がないため、グローバル変数とみなされ、その名前のグローバル変数はありません。

関連する問題