[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]  Lua Table
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

Lua Table

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

Posted by Tkl1129   Hong Kong  (43 posts)  [Biography] bio
Date Wed 10 Aug 2011 02:26 AM (UTC)
I'm try to use Lua table instead of SQLite, I've got a problem.

Case here:
I wanna search for some specific key inside.


Map = {}
	Map.sz = {}
		Map.sz.sz01 = {	Code = "sz01",
						Area = "sz",
						Location = "Tower",
						CP = 1,
						Range = 3,
		Map.sz.sz02 = {	Code = "sz02",
						Area = "sz",
						Location = "Hotel",
						CP = 0,
						Range = 4,
	Map.yz = {}
		Map.yz.yz01 = {	Code = "yz01",
						Area = "yz",
						Location = "Center",
						CP = 1,
						Range = 3,

By this table, If I only got 1 information, Location = "Center", how can I search back which Code of this area?
For example, "Search Location "Center" and then return the code "yz01"....that is what I want to get, but don't know how to do it in Lua, Thanks.
[Go to top] top

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #1 on Wed 10 Aug 2011 03:31 AM (UTC)

Amended on Wed 10 Aug 2011 03:33 AM (UTC) by WillFa


function ScanLocation(locStr)
  for area,areaTable in pairs(Map)do
    for code, codeTable in pairs(areaTable) do
      if codeTable.Location == locStr then
        return code

Since codeTable.Code is the same as the keyname of codeTable it'll work quicker. If you want to hard code it for clarity or fringe cases where your t.Code will be different, then return codeTable.Code instead... Also, if you start putting values in there there other than tables. (i.e. sz.Name = "Foo", sz.Builder = "Nick" or something) you'd want to wrap the second for in a if type(areaTable) == "table" check.
[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.


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.


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]