I want to be able to store information so that it will be accessible again after I've restarted Mudlet.
(It's going to be simple information, so I'm not looking to make a whole database or anything.
Sorry in advance if this is already in the manual. Please point me in the right direction.)
Say I have something like this:
if currenthealth/maxhealth < sippingpoint then sip(Health) end
And when I log in, I've already decided I want to sip at 50% health:
sippingpoint = 0.5
I can change sippingpoint to 10% or 75% or whatever while I'm playing, but it will eventually revert back to 50% next time.
How can I keep a variable/setting ...thing?
Storing Information
Re: Storing Information
Check out table.save(...) and table.load(...) in the api documentation. In a nutshell, you put your variables into a table and write this table to a file and load it in a new session.
-
- Posts: 20
- Joined: Sat Jan 29, 2011 12:05 am
Re: Storing Information
Hi I looked at table.save() and table.load() in the mudlet manual, but wasn't able to figure it out.
I created a table:
settings = {"on","off","off"}
Double checked to see that it was there; It was:
table {
1: 'on'
2: 'off'
3: 'off'
}
Then I tried:
table.save(getMudletHomeDir().."\\myfile","settings")
I closed Mudlet, saved my profile, reopened Mudlet and tried:
table.load(getMudletHomeDir().."\\myfile","settings")
To no avail. No file was created in that folder either.
Can you tell me what I've done wrong?
I created a table:
settings = {"on","off","off"}
Double checked to see that it was there; It was:
table {
1: 'on'
2: 'off'
3: 'off'
}
Then I tried:
table.save(getMudletHomeDir().."\\myfile","settings")
I closed Mudlet, saved my profile, reopened Mudlet and tried:
table.load(getMudletHomeDir().."\\myfile","settings")
To no avail. No file was created in that folder either.
Can you tell me what I've done wrong?
Re: Storing Information
I was giving this a little thought and threw this together for you....
It is a very simple database to store numeric variables in....
Paste the following into a script window and save it
OvarSave(key,value)
Where 'key' is any text value(name of your variable) and 'value' is any numeric value (will replace an existing value if any)
and
result = OvarGet(key)
This will save the variable in a database to be recovered whenever (even after restarting mudlet)
It is a very simple database to store numeric variables in....
Paste the following into a script window and save it
this will give you 2 new functions to use....
OvarSave(key,value)
Where 'key' is any text value(name of your variable) and 'value' is any numeric value (will replace an existing value if any)
and
result = OvarGet(key)
This will save the variable in a database to be recovered whenever (even after restarting mudlet)
-
- Posts: 20
- Joined: Sat Jan 29, 2011 12:05 am
Re: Storing Information
Thanks for taking the time to put the script together. It works great, even with some short strings I tried.
In the end, I was able to get table.load() and table.save() working afterall - I just needed to omit the quotes around the name of the table. ^^; a stupid mistake on my part.
so thank you both!
In the end, I was able to get table.load() and table.save() working afterall - I just needed to omit the quotes around the name of the table. ^^; a stupid mistake on my part.
so thank you both!
Re: Storing Information
Omit, what happens if i try to load a variable that wasnt' saved?
Re: Storing Information
Likely it will throw an error (I have not used the db functions in over a year and not at home to try it myself).
In order to "fix" that you would only need to check if results[1]==nil in the OvarGet function and return that case in whatever format you desire.
If that doesn't work for you, let me know and I will throw together anouther example. (I should have some time in the next few days.)
In order to "fix" that you would only need to check if results[1]==nil in the OvarGet function and return that case in whatever format you desire.
If that doesn't work for you, let me know and I will throw together anouther example. (I should have some time in the next few days.)
Re: Storing Information
I'm a fan of database storage myself, though you do have to take care to regulate your commits. Too many and your system slows down. Too few and you risk data loss.