[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Cycling through a Lua able in reverse.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Cycling through a Lua able in reverse.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Bobble   Canada  (76 posts)  [Biography] 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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] 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
[Go to top] top

Posted by Bobble   Canada  (76 posts)  [Biography] 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.
[Go to top] 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.


10,020 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]