Kingdaro wrote:I'm much more comfortable with using for i=1, #table [..] I never really bothered to get the concept of pairs/ipairs
Iterating arrays that way can be faster (eliminating iterator function call overhead), but only if you index the table you're iterating no more than ~1-2 times in the loop body, and it only works for arrays. For instance:
for i=1, #stars do
stars[i].y = stars[i].y+(speed*dt*(stars[i].size/2))
end
for i,star in ipairs(stars) do
star.y = star.y+(speed*dt*(star.size/2))
end
The second loop is faster, because we eliminate 3 table look-ups, which saves more time than we lose from the iterator call (I also find it easier to read).
bartbes wrote:Also, note that ipairs might get deprecated in lua 5.2.
Actually, they changed their minds. ipairs is staying.
It's a good call, Love people use so much ipairs than a lot of programs had to be revised (or use old Loves) just to use new Love versions with new Lua.
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------