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: Select all
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