hi all, just a quick question, I have a table with some sprites there, called birdList, if I iterate it from back to front, I can iterate it all and remove all like this:
count= #birdsList
for i=count, 1,-1 do
table.remove(birdsList, i)
end |
but the same list, if i iterate it from start to end i get an error, that one of them, the 6th is nil (i have 10 sprites there)
count= #birdsList
for i=1, count do
table.remove(birdsList, i)
end |
I've searched the forum for an answer to this behaviour in the for cycle, i couldnt find any, can someone explain to me whats happening
tnx in advance and sry about the noob question
Comments
The solution is to loop backwards
I thought I was controling the loop counter, with the
again, sry about the noob questions, but im writting this down so I wont forget lol, lua and its global scope is very different from what Im used to programming
tnx again
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
tnx again yep, thats what was happening to me, its a table with key value pairs, it was a noob mistake lol