Right now I’m doing some tests but I cant seem to find what is wrong with this code – any idea?
function IATetris(Pieza,Rotacion,Array)
io.write("The table the script received has: ",Pieza,"\n")
RotacionInicial = Rotacion
PosInicial = 7
final = #Array --this gets the size of the array
i = 1
for y = 1, 20 do --the array of my tetris board is 20 in x and 14 in y so it would be something like this Array2D[20][14]
io.write(" First for y ",y,"\n")
Array2D[y]={} --clearing the new array
for x = 1,14 do
io.write(" First for x ",x,"\n")
if i == final then break end
io.write(" First for i",i,"\n")
Array2D[y][x] = Array[i]
i= i+1 --seems like you cant use i++ in lua
end
end
end
What I’m doing is getting 2 integers and 1 Array. I’m having to write in the console to check where the program is actually going, and what I’m getting is…
The first log message: "The table the script received has: "
and the second log message: " First for y "
But I don’t get any further than those so probably the program is crashing there? This function is being called like every 20 seconds or so. I have really no idea why this is happening. Any help would be really appreciated, thank you.
If this line logs:
and this line does not log:
Then the problem is on one of these lines:
for x...definitely works for me, so I’d suggest it’s the Array2D line. There is nothing syntactically wrong with it, so it must be a runtime error. Runtime errors should be reported by Lua or the application it is embedded into. If they aren’t and the function just “stops” then you are debugging blind, and you will waste a lot of time on problems like this.The only error I can think might happen on that line would be if
Array2Dis not a table. Since you are trying to index it, it needs to be.Array2Disn’t declared in your function, this is fine if it is a global variable that is already defined elsewhere. However if it is meant to be a local variable just for this function then you should addlocal Array2D = {}to it.Without knowing what
Array2Dis, or what your actual error is even, it’s hard to give a more accurate answer. If you really have no better method of finding out the problem than logging, this, just before the Array2D line, should test my hypothesis: