That's something to do with Lua. The pairs() function in my understanding will not necessarily return key/value in any specific order, which kind of makes sense since a key could be anything from a table, function, etc.
If you are using normal numerical indexes though starting with 1, ipairs() should return them in order.
Personally I don't use the advanced "for in" loop just the basic for loop. Then you can index directly (provided your keys are numbers, as in your example):
for i=1,10do
a[i]=i+1endfor i=1,10doprint(i,a[i])end
This old fashioned method gives you complete control and (IMO) is much more readable.
WhiteTree Games - Home, home on the web, where the bits and bytes they do play! #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
I like the old style too but I think that handling objects with keys can be powerful like I've seen in Objective-C. For simple loops you can use the standard form.
Comments
If you are using normal numerical indexes though starting with 1, ipairs() should return them in order.
Likes: atilim
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Likes: talis
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Marc