Table loading and saving

Post Reply
Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Table loading and saving

Post by Manni »

I'm trying to create a script that will track the incoming and outgoing house members based on house logs in Achaea. Similar to how city Ambassadors do it, but I'm wanting to automate the tracking a bit, and maintain a database with it.

I'm wanting to load a table of the current year's house membership, and quits/suicides, but I'm not quite sure how to save or load tables, nor how they handle nested tables.

I'd like to be able to call a table say from y598 and compare it to the table from y599. handling the table itself won't be too difficult, but I'm wanting to maintain the data between sessions and I only know that table.save and table.load are the means to that, but everything I've read has been little help for me. Any help with this would be greatly appreciated.

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Table loading and saving

Post by Delrayne »

Code: [show] | [select all] lua
-- save a table
table.save(getMudletHomeDir().."/sometable.lua", targetTable)
This will save the TABLE 'targetTable' to the FILE 'sometable.lua' in the mudlet home directory of your current profile.
Code: [show] | [select all] lua
-- load a table
table.load(getMudletHomeDir().."/sometable.lua", targetTable)
-- You can load a table from anywhere on your computer, but it's preferable to have them consolidated somewhere connected to Mudlet.
This will load the TABLE 'targetTable' from the file 'sometable.lua' in the mudlet home directory.

All 'getMudletHomeDir()' does is return the file path for the mudlet home directory on your computer. So if you prefer to save your tables elsewhere, just change the file path to the appropriate location. This can be used in a type of application. IE. 'Triggers, Aliases, and Functions'. Just pick the method you are most comfortable with and test it out with a few a tables.

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: Table loading and saving

Post by Manni »

Is there some way to force a user confirmation for the save? For what I'm doing, I don't want to accidentally overwrite a table

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Table loading and saving

Post by Delrayne »

you could write in a script for it I suppose. Make an alias that displays the table to save and where it is to be saved, then ask yourself for a confirmation. If yes, run this function, if no return.

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: Table loading and saving

Post by Manni »

i'm just trying to figure out how to do that though. I know Rakon's GMCP inventory has something like that, bit i can't figure it out.

User avatar
Zaphob
Posts: 180
Joined: Wed May 09, 2012 8:07 am
Location: mg.mud.de

Re: Table loading and saving

Post by Zaphob »

Manni wrote:i'm just trying to figure out how to do that though.
Please show your latests tests and explain which problems you faced there exactly.

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: Table loading and saving

Post by Manni »

oh, no. the script in general works fine now, and I have an idea for the confirmation, but I just wondering if there was some sort of function in Mudlet or Lua that would be more efficient than activating and disabling an alias to check for the confirmation.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Table loading and saving

Post by demonnic »

So this spurred me to go ahead and make a package to aid in this sort of thing.

Clicky Clicky!

Post Reply