View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:33 pm



Reply to topic  [ 11 posts ] 
 How to: Tables 
Author Message

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post How to: Tables
i have a global table
indexes in this table are actor's IDs, so they stand not in a serial row

as i know the "for i = 0, #table do" cycle will stop if tried to acces a nil element

how can i cycle through the whole table?
maybe table.foreach?


Sun Mar 13, 2011 10:55 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: How to: Tables
"for i = 1, #table do" will cycle through all of the table's non-nil items, even if it bumps into a nil one in the middle of cycling.


Sun Mar 13, 2011 3:02 pm
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: How to: Tables
ok, i'll try again

another question:
is there any sense in using table.remove and table.insert?


Sun Mar 13, 2011 4:36 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: How to: Tables
Insert and remove can shift existing elements. You can read about it here: Lua 5.1 Reference Manual: Table insert


One important thing that you may or may not be aware of:
Lua Docs wrote:
An unsigned char specifying the MOID that this MovableObject is assigned for the current frame only.
In my experience the IDs usually stay the same between frames, but there are no guarantees.


Sun Mar 13, 2011 6:13 pm
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: How to: Tables
i don't use IDs of multi-framed MOs, but 1-framed actors' IDs
btw, thanks!


Sun Mar 13, 2011 8:47 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: How to: Tables
He means processing update frames.


Sun Mar 13, 2011 9:00 pm
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: How to: Tables
Roast Veg wrote:
He means processing update frames.

oh...

i think i've trapped on that thing (with IDs and frames), cause my script suddenly started to do weird things with an actor which it should ignore (which wasn't added to operated table too)


Tue Mar 15, 2011 2:43 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: How to: Tables
Question: Why store actor IDs at all? Why not just GetMOFromID so you have a stable pointer rather than an unstable MOID?


Wed Mar 16, 2011 2:48 am
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: How to: Tables
cause it's funny


Thu Mar 17, 2011 12:34 pm
Profile
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: How to: Tables
That's probably not a great way to make programming decisions.


Thu Mar 17, 2011 12:42 pm
Profile WWW

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: How to: Tables
nevermind. i've made it to work in some other way


Thu Mar 17, 2011 12:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.465s | 13 Queries | GZIP : Off ]