Help with code problem (still learning)

Hello, i would like some help with a problem i still learning so i will appreciate any help ty very much.

The problem is on this code:

if matchlist ~= nil then for i = 1, #matchlist do print('lista:'..#matchlist) print('size:'..matchlist[i].tamanho) print('X ultimo:'..matchlist[i].x) end end for i = 1, #matchlist do print('lista2:'..#matchlist) print('size2:'..matchlist[i].tamanho) print('X ultimo2:'..matchlist[i].x) end if tilelist ~= nil then tilelist = sc.RemoveCluster(tilelist,matchlist) -- inside this function end 

follows the function code:

function \_sc.RemoveCluster(tilelist,matchlist) for j = #matchlist,1,-1 do print('matchlistx:'..matchlist[j].x..','..matchlist[j].y..',')--..matchlist[j].tamanho) for i = #tilelist, 1, -1 do --print('tile x:'..tile[i].x) if tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then print("removed:"..tilelist[i].tipo ..'i'..i) display.remove(tilelist[i]) tilelist[i] = nil end end end return tilelist, matchlist end 

      I tried change but i could not properly understand the data flow, sometimes i feels there’s a problem with transferring data  on corona (of course is not the problem is on me) but the codes that works on love2d don’t work here and is something always of getting a nil value.

   any chance of someone explain why here i get so many “nil value” problem and on love2d i dint get … since both are LUA script?

   I’m going in circles  all the time. :frowning:

I’m not expert but I would rewrite if statement in _sc.RemoveCluster like that

if  tilelist[i] and tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then

to make sure tilelist[i] have not been  removed in previous loop iterations.

Sorry for my english:)

Idurniat, ty for the fast reply.

Friend, that was not removed thats to only remove code i have in all game, besides this i was making some tests and as i was suspecting some very particulary is happening ( since i’m not a good programmer i calling it some bugs)  but if you know maybe you can teach me the why its happening and how to avoid this to future improvement.

the code below is for some tests on the code from other reply i made.

function \_sc.RemoveCluster(tilelist,matchlist) for j = #matchlist,1,-1 do for i = #tilelist, 1, -1 do if tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then --display.remove(tilelist[i]) --tilelist[i] = nil print("tipo: "..tilelist[i].tipo) -- here print normally and that means the above is correct end end end return tilelist end

so if i can manage to get the “tilelist[i].tipo” this means that it exists on that part

But when i simple remove comments and remove the print  like this below:

function \_sc.RemoveCluster(tilelist,matchlist) for j = #matchlist,1,-1 do for i = #tilelist, 1, -1 do if tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then -- HERE ACUSES PROBLEM display.remove(tilelist[i]) tilelist[i] = nil --print("tipo: "..tilelist[i].tipo) end end end return tilelist end

Then i receive a “attempt to index a field ‘?’ (a nil value)”, so thats cleary shows something strange, maybe some gap on programming paradigms that i problema still dont know, but that kind of thing dont happens on c# or even love2d that still lua … this are taking my sleep away. 

I’m trying on the google for answers but since i even know to name the problem i’m not finding solutions.

Any help will by most appreciated.

If someone there knows what is happening.

ty again Idurniat

I’m not expert but I would rewrite if statement in _sc.RemoveCluster like that

if  tilelist[i] and tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then

to make sure tilelist[i] have not been  removed in previous loop iterations.

Sorry for my english:)

Idurniat, ty for the fast reply.

Friend, that was not removed thats to only remove code i have in all game, besides this i was making some tests and as i was suspecting some very particulary is happening ( since i’m not a good programmer i calling it some bugs)  but if you know maybe you can teach me the why its happening and how to avoid this to future improvement.

the code below is for some tests on the code from other reply i made.

function \_sc.RemoveCluster(tilelist,matchlist) for j = #matchlist,1,-1 do for i = #tilelist, 1, -1 do if tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then --display.remove(tilelist[i]) --tilelist[i] = nil print("tipo: "..tilelist[i].tipo) -- here print normally and that means the above is correct end end end return tilelist end

so if i can manage to get the “tilelist[i].tipo” this means that it exists on that part

But when i simple remove comments and remove the print  like this below:

function \_sc.RemoveCluster(tilelist,matchlist) for j = #matchlist,1,-1 do for i = #tilelist, 1, -1 do if tilelist[i].x == matchlist[j].x\*64 and tilelist[i].y == matchlist[j].y\*64 then -- HERE ACUSES PROBLEM display.remove(tilelist[i]) tilelist[i] = nil --print("tipo: "..tilelist[i].tipo) end end end return tilelist end

Then i receive a “attempt to index a field ‘?’ (a nil value)”, so thats cleary shows something strange, maybe some gap on programming paradigms that i problema still dont know, but that kind of thing dont happens on c# or even love2d that still lua … this are taking my sleep away. 

I’m trying on the google for answers but since i even know to name the problem i’m not finding solutions.

Any help will by most appreciated.

If someone there knows what is happening.

ty again Idurniat