Page 3 of 3
Re: Lua Generic for
Posted: Tue Dec 20, 2011 8:54 am
by Robin
Jasoco wrote:It has in my experience of sorting my objects by Y.
You can't depend on it, in the
documentation it says:
The order in which the indices are enumerated is not specified, even for numeric indices.
Re: Lua Generic for
Posted: Tue Dec 20, 2011 1:46 pm
by Nixola
slime wrote:Well, if you use a numeric for then you're probably going to be using the # operator on the table, and that will also not like gaps in the array part. Just try to either not have gaps in arrays (use table.remove), or discard the notion of iterating over the whole array sequentially if there are gaps. :p
I just tried table.remove... Now I don't have to use something that I hate
Thank you, Slime!
Re: Lua Generic for
Posted: Thu Dec 22, 2011 9:06 am
by Ensayia
Using table.remove instead of setting a particular index to nil will re-order your indices so there are no gaps as well.
Re: Lua Generic for
Posted: Fri Dec 23, 2011 12:25 am
by Jasoco
Robin wrote:Jasoco wrote:It has in my experience of sorting my objects by Y.
You can't depend on it, in the
documentation it says:
The order in which the indices are enumerated is not specified, even for numeric indices.
Well I'm just saying in all the time I've depended on it for making sure my objects are drawn from top to bottom even when moving around, I've never had it get out of order as long as I use pairs(). And this is with it sorting every single frame.
Personally, if table.sort didn't work right, I don't know what I would do.
Re: Lua Generic for
Posted: Fri Dec 23, 2011 7:47 am
by Robin
y'know, table.sort only works with indices 1 to #table -- are you sure you're not talking about ipairs?
Re: Lua Generic for
Posted: Fri Dec 23, 2011 9:08 pm
by Jasoco
I am sure. I have done it numerous times. My Adventure Engine proves that.
Re: Lua Generic for
Posted: Fri Dec 23, 2011 9:51 pm
by Robin
I probably misunderstood you. Could you please explain very clearly and carefully what you do then and what the result in?
I'd like to learn something new.
Re: Lua Generic for
Posted: Fri Dec 23, 2011 10:40 pm
by Xgoff
if you're getting a meaningful iteration order out of pairs then that means you're either really lucky or it's not actually working like you think it is but haven't seen it mess up yet
the fun starts when the table rehashes
Re: Lua Generic for
Posted: Sat Dec 24, 2011 2:19 am
by slime
The fun starts when you switch Lua versions or implementations and you wonder why seemingly random bugs occur at seemingly random times.