[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]  Using Tables to Create a Player database
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Using Tables to Create a Player database

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


Posted by Dpw3868   (6 posts)  [Biography] bio
Date Fri 04 Dec 2009 06:48 AM (UTC)
Message
Hi, I am new to mushclient and using lua.

Not sure exactly where to start but i want to make an alias that allows me to add a players Name, class, and clan to a table.

I've been looking around and i guess it would look something like this

Alias playeradd * * *

-- playeradd Joe Mage BIGCLAN
player = player or {}

x = %1
player = %1 -- Joe ?

player[x].class = %2 -- Mage ?
player[x].clan = %3 -- BIGCLAN

Not sure if this is right, where i would put this in the program or anything like that.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Fri 04 Dec 2009 09:52 PM (UTC)
Message
You need to decide if you want to "key" on the player name or not (probably you do, so you don't get two of the same name in your table). You really want a table of tables. eg.


players = players or {}  -- make players table if not already there

local name = "%1"

players [name:lower ()] = { class = "%2", clan = "%3" }


Note you need to quote the wildcards, as they are strings.

I have forced the name to lowercase to make sure that Joe and joe are stored in the same place.

The players table is the table of all players, and each entry has the player name as the key. For each player there is another table, which has two entries, class and clan.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dpw3868   (6 posts)  [Biography] bio
Date Reply #2 on Fri 11 Dec 2009 10:05 PM (UTC)
Message
Thank you Nick for the helpful response.

I used the script you wrote and it works great.

I wrote another basic script using your tprint function to output the table.

I would to know use this information to highlight peoples names on the mud by the clan affiliation.

Is this possible and what should i read up on?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sat 12 Dec 2009 12:05 AM (UTC)

Amended on Sat 12 Dec 2009 12:08 AM (UTC) by Nick Gammon

Message
This looks similar:

Template:post=9909 Please see the forum thread: http://gammon.com.au/forum/?id=9909.


or

Template:post=9903 Please see the forum thread: http://gammon.com.au/forum/?id=9903.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dpw3868   (6 posts)  [Biography] bio
Date Reply #4 on Wed 16 Dec 2009 09:25 PM (UTC)
Message
I am now able to make the table, but How do i save the table from 1 session to the next?

Thanks

Dan
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 16 Dec 2009 10:05 PM (UTC)
Message
Template:post=4960 Please see the forum thread: http://gammon.com.au/forum/?id=4960.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 17 Dec 2009 03:46 AM (UTC)
Message
Another approach, which might be simpler and possibly safer in case of program crashes, is to use SQLite (ie. a database). For some details and examples see:

http://www.gammon.com.au/db

and

http://www.gammon.com.au/sql

You could set up a database containing a table of players, clans etc., and add to that as required. Then you can use a SQL query to find players in a particular clan, or meeting certain requirements (eg. a level range).

- 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.


3,685 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]