How to access an array with numerical key in lua.

Hi, I’m stock with trying to access the next row in an already created lua table or array.

for m = 1, 8 do

  local str = " "

  for n = 1, 7 do

    if thing[m][n].touchable == 0 then

      thing[m+1][n].touchable = 0 --[[Here is where i get error, attempt to index field, a nil value. But i have already created the array which is an array of 8 by 7 rect object, with a touchable property.]]–

    end

    str = str…thing[m][n].touchable…" "

  end

  print( str )

end

How can i access the next row? Please i need help, thanks.

Your code is correct in that the notation is indeed something like myArray[m][n] to retrieve element n in row m.

However, you are calling m+1 as row number. If m goes to 8, then m+1 will go to 9, and your 8 by 7 array will return nil.

@thomas6, a thousand thanks to you. 100% solved, let the dev continue…!!!

You’re welcome! On a side note: your question and short code snippet was the perfect way to ask for help. If you ask questions like this you’ll likely get great anwsers in no time, so don’t hesitate. It might speed up your development significantly.

Your code is correct in that the notation is indeed something like myArray[m][n] to retrieve element n in row m.

However, you are calling m+1 as row number. If m goes to 8, then m+1 will go to 9, and your 8 by 7 array will return nil.

@thomas6, a thousand thanks to you. 100% solved, let the dev continue…!!!

You’re welcome! On a side note: your question and short code snippet was the perfect way to ask for help. If you ask questions like this you’ll likely get great anwsers in no time, so don’t hesitate. It might speed up your development significantly.