forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

attempt to index field `?' (a nil value)...not true...help!!

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
ZORDAK



Joined: 21 Jan 2006
Posts: 12
Location: Spain

PostPosted: Sat Jan 21, 2006 10:14 am    Post subject: attempt to index field `?' (a nil value)...not true...help!! Reply with quote

Hi all.

Im making a blocks game,making the code for the elimination cubes i got some extrange problems.

First thing i have a table o 18x9 (tablero), resuming my code, i have 2 variable casilla_X and casilla_Y, thats indicates the cell position onthe table.The function comprobar_puntos() check the horizontal and vertical cell surrounded by the pressed cell, if any of the other cell have the same color i use mira_puntos() to save the position value in a temporal buffer if the value isnt on it.The i will do the same with the values in the buffer when finish i will delete into the original table etc etc....

The code isnt finished, because it check all the board and dont skip the borders btw is not the problem, the real problem is when i check the right zone , with the 4 call, it send the correct value to mira_puntos() but when enter on it it say attempt to index field `?' (a nil value), i checked the values with a trace and values al correct and i got the values directly from the table tablero [16][3] for example and all went ok.

I dont know what to do, is very extrange.



Here is my emilination code

Code:


function eliminacion()
   
  color_borrar=tablero[casilla_X][casilla_Y]
  coorx=casilla_X
  coory=casilla_Y
 
  fuera=false   
 
  indice_mirado=0
 
  repeat   
   
    indice=table.getn(temporal)+1
   
    tenemos=comprobar_puntos()
   
     if tenemos=="no" and indice==1 then
        fuera=true   
   else
          
        indice_mirado=indice_mirado+1   
      
          if string.len(temporal[indice_mirado])>2 then
             coorx=string.sub(temporal[indice_mirado],1,2)
             coory=string.sub(temporal[indice_mirado],-1)
          else
             coorx=string.sub(temporal[indice_mirado],1,1)
             coory=string.sub(temporal[indice_mirado],-1)
          end

         
        end
   
       
   if indice_mirado>=indice then
      fuera=true
   end
     
       
  until fuera==false   
    
end


function comprobar_puntos()
   
   local cuan=4
   local eso
   --ARRIBA DEL SELECCIONADO
    
   coory_a=coory-1
   coorx_a=coorx
   val=mira_puntos()
   
     if val=="no" then
      cuan=cuan-1
   end
     
     --ABAJO DEL SELECCIONADO
   
     coory_a=coory+1
   coorx_a=coorx
     val=mira_puntos()
     if val=="no" then
      cuan=cuan-1
   end

   --IZQ DEL SELECCIONADO
   coorx_a=coorx-1
   coory_a=coory
   val=mira_puntos()
     if val=="no" then
      cuan=cuan-1
   end
   
   --DERECHA DEL SELECCIONADO
   coorx_a=coorx+1
   coory_a=coory
   val=mira_puntos()
     if val=="no" then
      cuan=cuan-1
   end
   
     if cuan==0 then
        eso= "no"
     else
        eso= "si"
        cuan=0
     end
     
     return eso
end



function mira_puntos()

   local tiene=si
   
   veces=veces+1   
   
   esta=false
   if tablero[coorx_a][coory_a]==color_borrar then
      for i=1,table.getn(temporal) do
         if temporal[i]==coorx_a..coory_a then
            esta=true
         end            
      end
      if esta==false then
         temporal[indice]=coorx_a..coory_a
         esta=false
      end
    else
      tiene="no"
   end
   
    return tiene
end



I hope someone can help.[/code]
Back to top
View user's profile Send private message Visit poster's website
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Sat Jan 21, 2006 11:04 am    Post subject: Reply with quote

LUA table indexes start with 1, not 0 like (almost) every other language
Back to top
View user's profile Send private message
ZORDAK



Joined: 21 Jan 2006
Posts: 12
Location: Spain

PostPosted: Sat Jan 21, 2006 12:00 pm    Post subject: Reply with quote

???żżż i dont use the index 0, all the code is using 1 as first index of the array.

some help please?
Back to top
View user's profile Send private message Visit poster's website
ZORDAK



Joined: 21 Jan 2006
Posts: 12
Location: Spain

PostPosted: Sun Jan 22, 2006 12:48 am    Post subject: Reply with quote

28 visits ...

Nobody can help please?
Back to top
View user's profile Send private message Visit poster's website
soulphalanx



Joined: 22 Aug 2005
Posts: 35

PostPosted: Sun Jan 22, 2006 2:08 am    Post subject: Reply with quote

i think in LUA, its [y][x], not [x][y]

dont know if that helps

ive had a problem like this before, dunno if shine changed it
Back to top
View user's profile Send private message
ZORDAK



Joined: 21 Jan 2006
Posts: 12
Location: Spain

PostPosted: Sun Jan 22, 2006 2:15 am    Post subject: Reply with quote

Code:


function crea_tablero()
      
   for x=1,18 do
     tablero [x] = {}
     for y=1,9 do
         tablero[x][y] = math.random(numero_colores)
     end
   end
end



Im using x,y i can read all the values and send it to screen....dont unsderstand what happened.
Back to top
View user's profile Send private message Visit poster's website
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Tue Jan 24, 2006 7:43 am    Post subject: Reply with quote

Simple thing to double check variables is
Code:

if not value then
 -- call error here
end
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Jan 24, 2006 8:00 am    Post subject: Reply with quote

The problem was solved, ZORDAK mixed strings and numbers for indexing into the table. But if I understand the problem correctly, ZORDAK wanted to fill a vertically and horizontally connected part of a board of the same color. Here is a nice recursive solution:

Code:

function printBoard(board)
   local height = table.getn(board)
   local width = table.getn(board[1])
   for y = 1, height do
      local line = ""
      for x = 1, width do
         if board[y][x] == 1 then
            line = line .. "#"
         else
            line = line .. "."
         end
      end
      print(line)
   end
end

board = {
   { 0, 0, 0, 0, 0, 0, 0, 0},
   { 0, 0, 1, 1, 0, 1, 0, 0},
   { 0, 0, 1, 1, 1, 1, 1, 0},
   { 1, 1, 1, 0, 0, 1, 0, 0},
   { 1, 0, 1, 0, 1, 0, 0, 0},
   { 0, 0, 1, 1, 0, 0, 1, 0},
   { 0, 1, 1, 0, 0, 1, 1, 0},
   { 0, 0, 0, 0, 1, 1, 1, 0}}

function inBound(lower, value, upper)
   return value >= lower and value <= upper
end

function fillBoard(board, x, y, fillColor)
   local height = table.getn(board)
   local width = table.getn(board[1])
   if inBound(1, x, width) and inBound(1, y, height) and board[y][x] ~= fillColor then
      local cellColor = board[y][x]
      board[y][x] = fillColor
      return  1 +
         fillBoard(board, x + 1, y, fillColor) +
         fillBoard(board, x - 1, y, fillColor) +
         fillBoard(board, x, y + 1, fillColor) +
         fillBoard(board, x, y - 1, fillColor)
   end
   return 0
end

print("original board:")         
printBoard(board)
local x = 4
local y = 3
print("filling at (" .. x .. ", " .. y .. ")")
count = fillBoard(board, x, y, 0)
print("filled cells: " .. count)
print("filled board:")
printBoard(board)


Code:

original board:
........
..##.#..
..#####.
###..#..
#.#.#...
..##..#.
.##..##.
....###.
filling at (4, 3)
filled cells: 18
filled board:
........
........
........
........
....#...
......#.
.....##.
....###.
Back to top
View user's profile Send private message
ZORDAK



Joined: 21 Jan 2006
Posts: 12
Location: Spain

PostPosted: Tue Jan 24, 2006 2:55 pm    Post subject: Reply with quote

Yes, tablero [0] isnt the same that tablero["0"].

Thanks shine.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group