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
➜ about global variables and tables
about global variables and tables
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Graceecat
Taiwan (15 posts) Bio
|
Date
| Sun 13 May 2007 08:10 AM (UTC) |
Message
| My global variables and tables vanished after restarting the mushclient. How do you save them? Question 2: how do you show them all? tks!
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 13 May 2007 08:41 AM (UTC) |
Message
| |
Posted by
| Graceecat
Taiwan (15 posts) Bio
|
Date
| Reply #2 on Sun 13 May 2007 11:35 AM (UTC) |
Message
| According to question 2, I wrote my codes as follows:
require "serialize"
print (serialize.save ("_G"))
However it had a Run-time error.
World: aaa
Immediate execution
C:\mushclient407\MUSHclient\lua\serialize.lua:176: Cannot serialize '_G.progress.new' (function)
stack traceback:
[C]: in function 'error'
C:\mushclient407\MUSHclient\lua\serialize.lua:176: in function 'save_item'
C:\mushclient407\MUSHclient\lua\serialize.lua:169: in function 'save_item'
C:\mushclient407\MUSHclient\lua\serialize.lua:169: in function 'save_item'
C:\mushclient407\MUSHclient\lua\serialize.lua:61: in function 'save'
[string "Alias: "]:3: in main chunk
| Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #3 on Sun 13 May 2007 12:58 PM (UTC) |
Message
| You have to serialize the variables, not the whole script. Just go through whatever variables are needed between sessions, serialize those, and store them in MUSHclient variables with SetVariable(). Also keep in mind that there is a _G within _G, so referencing that as a whole can result in an infinite loop depending on what you're doing.
A good way to just store all the variables would be to go through for i,v in pairs(_G) and store anything where v is not a function, and i is not _G. |
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 #4 on Sun 13 May 2007 08:51 PM (UTC) |
Message
| The link I gave you had these sentences in it:
However, serializing (saving) the _G table is not really practical, as it contains things like functions, which cannot be serialized.
Thus, I recommend you place all variables needed for scripts into their own table.
Did you not read that bit?
All you have to do is store your variables in their own table, and serialize that.
|
- 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.
17,762 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top