[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]  Adding Store Items to a table
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Adding Store Items to a table

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


Posted by Rene   (22 posts)  [Biography] bio
Date Sun 08 Oct 2017 12:57 PM (UTC)
Message
So I am trying to capture a list of items in a store and then store it myself in a table.
I got the capture going, and it now captures 'name' for the item name, 'type' for the item type and 'amount' which is a number of the amount, i.e. name = 'sword', type = 'weapon' and amount = '3'.
I want to add that to an array so I can have this capture all the items in the store into that array, how would I do that?
Also, how can I have it later do something list 'list sword' and it will list everything that matched sword?
THank you.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 10 Oct 2017 08:02 PM (UTC)
Message
See my post about Lua tables: http://www.gammon.com.au/forum/?id=4903

And also: http://www.gammon.com.au/forum/?id=6036

Basically you would make a table of tables.

For example:


itemsTable = { }  -- make table of all items in store

-- for each item:

newItem = { }  -- empty table

newItem.name = 'sword'
newItem.type = 'weapon'
newItem.amount = 3


table.insert (itemsTable, newItem)

newItem = { }  -- empty table

newItem.name = 'knife'
newItem.type = 'weapon'
newItem.amount = 4

table.insert (itemsTable, newItem)


require "tprint"

tprint (itemsTable)  -- view table

-- look through table:

for k, v in ipairs (itemsTable) do

  print ("name =", v.name)
  print ("type =", v.type)
  print ("amount =", v.amount)

end -- for each item

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[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.


769 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]