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
➜ Tips and tricks
➜ Saving variables and arrays
Saving variables and arrays
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Tue 05 Nov 2002 05:17 PM (UTC) |
Message
| I need help with this. I need to make a plugin that keeps count of all your eq's hits and Armor Class, etc, and I need to save it across sessions. I guess file access would be impossible, but I think maybe we could have a basic repository in a file, different for each world, that saves the specific script's/plugin's info, for example 'world.appendtofile "text"', etc... Or am I wrong, and you can save plugin variables?
Please help me with this. |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Tue 05 Nov 2002 09:46 PM (UTC) |
Message
| A plugin will save all its variables if you have "save_set" set. That is, this line as part of the <plugin> element ...
save_state="y"
The state is saved on a per-world basis with a rather long file name which is the plugin ID concatenated with the world ID, like this:
dc68d2c6f8b154d243e917bc-2adec0ac37689537f9e3daf2-state.xml
Each plugin can have any number of variables, and each variable can be any size (including multiple lines) so that should be adequate for keeping track of your data. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #2 on Tue 05 Nov 2002 09:57 PM (UTC) |
Message
| Ahh, i thought so when i saw the files... OK, thanks a lot for the tip, this helped a lot :) |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #3 on Wed 06 Nov 2002 11:57 AM (UTC) |
Message
| I don't know about your copy of MUSHClient, but I just spent 2 days making a plugin only to find out that it doesn't save the internal array that i have stored all my data in, even with save state on... What am I not getting? |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #4 on Wed 06 Nov 2002 12:54 PM (UTC) |
Message
| You have to save the data to a MushClient variable.
If it is an array(and you're using VBScript), you can use split() and join() to move the data around between the array and a pure string that MushClient variables want.
I'm sure all the languages have a capability to do this as well. | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #5 on Wed 06 Nov 2002 01:04 PM (UTC) |
Message
| I could do that, yes, but my table may be very long, maybe up to 10KB, and I don't know how much data MUSHclient variables can hold :( |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Vaejor
(120 posts) Bio
|
Date
| Reply #6 on Wed 06 Nov 2002 01:54 PM (UTC) |
Message
| MushClient doesn't save variables from the scripting languages, so this is one of the only ways to do what you're looking for.
The only other option that comes to mind is dumping it to a text file and reading that instead of using MushClient variables.
Unless you wanted to design a true DB interface in which you could save and access data (?most) effectively considering large amounts of data and longterm storage.
If someone else knows of another way, perhaps they'll share with us.
| Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #7 on Wed 06 Nov 2002 03:22 PM (UTC) |
Message
| Actually it is a multidimensional array, which cannot be "Split" and "Join"ed, but in the end I just saved it as many variables (one for each column). |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #8 on Wed 06 Nov 2002 05:32 PM (UTC) |
Message
| You're situation seems a little similar to the one I was facing when I was developing my "AOD_EQ" plugin. Basically, I had a relatively large amount of data I wanted to store in a single record, and the number of records could concievably be as large as the user wants.
At the time, I felt that there would be too much overhead in storing every single record in MUSHclient variables. It would mean that the MUSHclient plugin would be storing 30 to 60 variables per record (or more), and in my case, I have about 5 different sets of EQ, so the plugin would have needed to store over 250 variables.
Instead, what I decided to do was write each set of eq to a text file. The plugin then writes and reads the text file as required. If you would like to see my plugin that does this, you can download it from my website. The URL is in my signature below.
Eventually, I may decide that I want to maintain a very large database of the items available in the game. In order to accomplish this, I would likely try and write an interface to a professional database program, like Microsoft Access, for example.
A few people have dabbled with this here, including Nick, but no one (to my knowledge) has actually written a useful plugin that uses a database. There is quite a long thread on the matter somewhere here in the forums.
Personally, I've become somewhat bored with 'my' MUD, so I barely play there anymore, compared to how much I used to. As expected, script writing has been nil for quite some time. (Had I kept pace, I probably would have a plugin that uses a database written by now). |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #9 on Wed 06 Nov 2002 10:24 PM (UTC) |
Message
| The intention was that in the plugin you would use OnPluginInstall to move variables from the MUSHclient variables to your scripting variables (if required) and OnPluginSaveState to move them back again prior to the plugin's state being saved.
A database is probably the way to go for a lengthy number of variables, we had some useful snippets a while back, perhaps I'll make them into a plugin so the whole idea is collected into one place.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #10 on Thu 07 Nov 2002 01:59 AM (UTC) |
Message
| I have now written a lengthy plugin to demonstrate creating a database, creating a table, adding data, getting it back, deleting it, and general actions on it.
See Plugin that accesses a database
|
- 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.
33,481 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top