saving variables

Denarii
Posts: 111
Joined: Thu Dec 03, 2009 10:54 pm

Re: Weird errors

Post by Denarii »

I already have, in the latest LuaGlobal it's _Echos

tarrant
Posts: 49
Joined: Thu Apr 15, 2010 10:36 pm

Re: Weird errors

Post by tarrant »

Heiko wrote:You forgot to specify which table you want to save. The syntax is: table.save( path, myTableThatIwantToSerialize )
The same applies to table.load(). Those are general functions that can be used to serialize any Lua table or restore the data from a file to any given table. When restoring a table from file you need to tell the function which table you want to hold the content as the table name is not part of the file.
in a post you made here, you said if table isn't specified, then it'll just save everything. i thought that would be easier. or did i misunderstand what you said?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Weird errors

Post by Heiko »

Oh I see. This information is outdated because I've changed Mudlet's script initializations and profile loading code in the meantime. You are right. There used to be a second undocumented function that was intended to be used by Mudlet itself to store all global variables in _G. I've dropped this idea though because of various reasons. I don't remember if this function is still part of LuaGlobal -> please check the source of LuaGlobal.lua Normally, Mudlet's API is never changed to guarantee that old scripts still work on newer releases, but as this function has never been publicly documented, it may have been removed.

In any case I strongly advise against using it because I've changed Mudlet's script loading in the meantime which may lead to very unexpected results if this function is being used.

Today, the recommended approach is to use table.save( filepath, table ).

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Weird errors

Post by Vadi »

That'd explain some odd global overwrite issues people were having then, when they were mis-using the function.

tarrant
Posts: 49
Joined: Thu Apr 15, 2010 10:36 pm

Re: Weird errors

Post by tarrant »

Ah, i see. Ok thanks for clarifying.

How do i create this table to save?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Weird errors

Post by Heiko »

You pass a filepath and a reference to a table to table.save() e.g. table.save(getMudletHomeDir().."/myVars.data", tableThatContainsMyPermVariables )

tarrant
Posts: 49
Joined: Thu Apr 15, 2010 10:36 pm

Re: Weird errors

Post by tarrant »

do you mean that i don't need to manually create my own table and add my variables in?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Weird errors

Post by Heiko »

No, you can save any table in the global namespace.

Post Reply