Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Cycling through a Lua able in reverse.
Cycling through a Lua able in reverse.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Bobble
Canada (76 posts) Bio
|
Date
| Wed 09 Sep 2009 03:14 AM (UTC) |
Message
| Greets everyone.
I was wondering if anyone knew of a way to cycle through a lua table starting with the last element and then proceeding down to the first.
The reason I ask is I am creating a table using "GetCommandList" and cycling through it using a for .. in .. do loop. However this creates a situation where the it starts with the most recent command, the next most recent etc. I want it to start with the least recent, the next least recent and so on.
Does anyone have an idea of how to do this. I'm imagining this will be pretty simple, but it escapes me right now. |
Open the watch. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Wed 09 Sep 2009 03:53 AM (UTC) Amended on Wed 09 Sep 2009 03:56 AM (UTC) by David Haley
|
Message
| If the table is an array (that is, it has numeric indices, not arbitrary keys) you can do the following:
local t = get_the_table
for i = #t, 1, -1 do
elem = t[i]
-- do something with elem
end
|
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Bobble
Canada (76 posts) Bio
|
Date
| Reply #2 on Wed 09 Sep 2009 04:38 AM (UTC) Amended on Wed 09 Sep 2009 04:39 AM (UTC) by Bobble
|
Message
| Hi David,
That seems to work perfectly. Thanks a bunch.
Take care! |
Open the watch. | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
20,725 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top