2012-11-03 2 views
2

이 코드가 계속 나타나지만 오류가 무엇인지 확실하지 않습니다. 누군가 그것을 알아내는 것을 도와 주실 수 있습니까? 그것이 64 행에 있다고합니다. 죄송합니다. 코드에 넣는 방법을 모르겠습니다. 다음은 오류 라인 코드입니다.LUA 오류 코드 64 : '?'필드를 색인화하려고 시도합니다. (없음 값)

 if (array[j][1] < smallest) then 

      smallest = array[j][1] 
      index = j 
     end 




--------- [ Element Data returns ] --------- 
local function getData(theElement, key) 
    local key = tostring(key) 
    if isElement(theElement) and (key) then 

     return exports['[ars]anticheat-system']:c_callData(theElement, tostring(key)) 
    else 
     return false 
    end 
end 

-------------- [ Scoreboard ] --------------- 
local screenX, screenY = guiGetScreenSize() 

local width, height = 300, 420 
local x = (screenX/2) - (width/2) 
local y = (screenY/2) - (height/2) 

local logowidth, logoheight = 275, 275 
local logox = (x/2) - (logowidth/2) 
local logoy = (y/2) - (logoheight/2) 

local isEventHandled = false 
local page = 1 

local a = { "Z", "W", "Y", "G", "H", "L", "P", "A", "B" } 
function getPlayerIDTable() 

    local array = { } 

    for key, thePlayer in ipairs (getElementsByType("player")) do 

     local playerID = tonumber(getData(thePlayer, "playerid")) 
     if (playerID) then 

      array[#array + 1] = { playerID, thePlayer } 
     end 
    end 

    for i = 1, 9 do 

     local j = math.random(1, 9) 
     if (array[i] == nil) then 

      array[i] = { j, a[ math.random(1, 9) ] } 
     end 
    end 

    return array 
end 

local players = { } 
function assemblePlayersByID() 

    local array = getPlayerIDTable() 
    local smallest, index, tempo 

    for i = 1, #array do 

     smallest = array[i][1] 
     index = i 

     for j = i + 1, #array do 
      if (array[j][1] < smallest) then 

       smallest = array[j][1] 
       index = j 
      end 
     end 

     -- flip arrays 
     tempo = array[i] 
     array[i] = array[index] 
     array[index] = tempo 
    end 

답변

2

이 오류는 사용자가 nil 값을 인덱싱하려고한다는 것을 의미합니다.

if (array[j][1] < smallest) then 

array[j]이 전무하다는 것을 의미 : "64 라인"이라고 가정

당신이 게시 코드에서 첫 번째입니다 배열의 인덱스 J과 값이없는 즉,있다.

if array[j] and array[j][1] and array[j][1] < smallest then 

참고 배열 [J]와 배열 [J] [1], 배열 [j]가 배열 [J] 존재하지만 경우 때문에 [1 모두 테스트해야한다 :이처럼 확인 할 수 있습니다 ], <을 비교하면 attempt to compare nil with number 오류가 발생합니다.

관련 문제