Lua Generic for

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua Generic for

Post 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.
Help us help you: attach a .love.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Lua Generic for

Post 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 :ultraglee: Thank you, Slime!
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: Lua Generic for

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Lua Generic for

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua Generic for

Post by Robin »

y'know, table.sort only works with indices 1 to #table -- are you sure you're not talking about ipairs?
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Lua Generic for

Post by Jasoco »

I am sure. I have done it numerous times. My Adventure Engine proves that.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Lua Generic for

Post 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.
Help us help you: attach a .love.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Lua Generic for

Post 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
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Lua Generic for

Post by slime »

The fun starts when you switch Lua versions or implementations and you wonder why seemingly random bugs occur at seemingly random times. ;)
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Semrush [Bot] and 4 guests