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
➜ Trouble Serializing a Table for Storage
Trouble Serializing a Table for Storage
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Noredil
(4 posts) Bio
|
Date
| Tue 12 Feb 2008 08:47 PM (UTC) |
Message
| I've been poking around on the forums here, learning how to serialize variables I'll need to use across sessions. I found an example in another thread which seemed to do exactly what I needed, but I get a runtime error trying to duplicate it.
I created this simple alias to play around with and try and get this to work. Here's the current alias and the error I'm getting.
function setvar()
luaenemies = {billy, bob}
require "serialize"
SetVariable("enemylist", serialize('luaenemies'))
end
And the error...
Run-time error
Plugin: LidSys (called from world: Achaea)
Function/Sub: setvar called by alias
Reason: processing alias ""
...\worlds\plugins\MyAchaea\modules\scripts\enemies.lua:26: attempt to call global 'serialize' (a table value)
stack traceback:
...\worlds\plugins\MyAchaea\modules\scripts\enemies.lua:26: in function <...\worlds\plugins\MyAchaea\modules\scripts\enemies.lua:21>
Any ideas why this won't work for me? | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #1 on Tue 12 Feb 2008 11:42 PM (UTC) |
Message
| Your quotes are all in funky places, unless "billy" and "bob" are variables and not strings, and "luaenemies" is a string and not a variable.
function setvar()
luaenemies = { "billy", "bob" }
require "serialize"
SetVariable("enemylist", serialize( luaenemies ) )
end
|
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Wed 13 Feb 2008 12:04 AM (UTC) |
Message
| You actually need to call something in the serialize table. Try this:
require "serialize"
luaenemies = { "billy", "bob" }
SetVariable("enemylist", "luaenemies = " .. serialize.save_simple ( luaenemies ) )
This calls "save_simple" inside the serialize table, to set the variable (which now looks like this):
luaenemies = {
[1] = "billy",
[2] = "bob",
}
And to get it back next time:
assert (loadstring (GetVariable ("enemylist"))) ()
That loads the string back into the Lua variable luaenemies. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Noredil
(4 posts) Bio
|
Date
| Reply #3 on Thu 14 Feb 2008 06:58 AM (UTC) |
Message
| Finally got it nailed down. Thanks guys, it looks like my quotes were what was really throwing me off. Serialize didn't do quite what I wanted it to, so I ended up doing a SetVariable with a table.concat and pipes to get it lined up. | 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.
15,373 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top