Ini files in mush?

Posted by Ogomez92 on Sat 24 Apr 2010 11:42 AM — 4 posts, 17,339 views.

#0
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.
USA #1
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.
#2
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. :)
USA #3
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. :)