[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  about global variables and tables
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

about global variables and tables

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Graceecat   Taiwan  (15 posts)  [Biography] 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!


[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 13 May 2007 08:41 AM (UTC)
Message
Read:

http://www.gammon.com.au/forum/?id=6030

Scroll down to the part about "serializing variables".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Graceecat   Taiwan  (15 posts)  [Biography] 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


[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] 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.


3,653 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]