Register forum user name Search FAQ

Gammon Forum

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 ➜ Using Tables to Create a Player database

Using Tables to Create a Player database

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


Posted by Dpw3868   (6 posts)  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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by Dpw3868   (6 posts)  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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by Dpw3868   (6 posts)  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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  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
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.


23,836 views.

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

Go to topic:           Search the forum


[Go to top] top

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