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 ➜ Ini files in mush?

Ini files in mush?

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


Posted by Ogomez92   (42 posts)  Bio
Date Sat 24 Apr 2010 11:42 AM (UTC)
Message
Hi,
Is there a way that I can use ini files in mushclient? Preferrably with lua, but I guess I can make a plugin in another language if it's going to let me use ini files.
What do you guys think it's the best way?
Since I have no idea of how to use sql, and I don't need searching and stuff I just need to save/load equipment sets and I want them to save.
Thanks in advance.
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Sat 24 Apr 2010 06:55 PM (UTC)
Message
Why not use plain Lua tables, and serialize them with serialize.lua?

require "serialize"

equipment = {
  [1] = {
    head = "helmet123",
    torso = "platemail456",
    hands = "gauntlets789",
  }
}

-- In a plugin, you'd probably want to do this within OnPluginSaveState.
local data = serialize.save_simple(equipment)

print(data)
-- This is what the serialized data looks like:
--[[
{
  [1] = {
    hands = "gauntlets789",
    torso = "platemail456",
    head = "helmet123",
    },
  }
--]]
-- Almost exactly what it originally was, but serialized as a string.

-- It's up to you where to actually put the data. I prefer using a MUSHclient
-- variable (SetVariable("name", "data")), which is saved between sessions in
-- the world, and is saved automatically in plugins if you have save_state="y"
-- in the plugin header.
SetVariable("mydata", data)


-- To later load it (in a plugin, OnPluginInstall would be best), do:
local data = GetVariable("mydata")
equipment = assert(loadstring(data))()

-- At this point, the 'equipment' table is exactly as it was in the beginning.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Ogomez92   (42 posts)  Bio
Date Reply #2 on Sat 24 Apr 2010 08:48 PM (UTC)
Message
Hi,
Thanks for the hint. I did not realize I could do that. I didn't even know what seraizlie did until now. So you're saying that serialize converts table data into a string?
Also what do the codes mean to the right of the eq like gauntlets413? is this something extra you put? Or do I need to put it.
Thanks. :)
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #3 on Sat 24 Apr 2010 08:58 PM (UTC)
Message
Ogomez92 said:
So you're saying that serialize converts table data into a string?

Yep. A table {1, 2, 3} becomes the string "{[1] = 1, [2] = 2, [3] = 3}"... not counting extra newlines and indentation.

Ogomez92 said:
Also what do the codes mean to the right of the eq like gauntlets413? is this something extra you put? Or do I need to put it.

Just something extra I put as an example. The table above theoretically represents a list of equipment sets with slots like head, torso, gloves. The values associated with those slots are strings representing the specific items in the MUD. (Useful for a command like "equip gloves789".) It's just an example, but I hoped it would be helpful anyways. :)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
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.


12,882 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.