Help - Search - Members - Calendar
Full Version: Mush Savevar And Loadvar Aliases
Achaea's Forums > Off-Topic > Tech Support > Client Help
Dontarion
So I wanted to be able to save arrays over different MUSH loadings without dealing with saving to files. In order to accomplish this I created two aliases.

You need to create two variables (IsKey, ArrayKeyToUse) to use the following code. This one is the loadvar alias. I use ^loadvar (.+?)$ in REGEX for the alias.
CODE
SetVariable("IsKey", 1)
SetVariable("ArrayKeyToUse", "")
if GetVariable("%1") == nil then
    Note("That variable doesn't exist - can't load variables from it.")
else
    if ArrayExists("%1") == false then
        ArrayCreate("%1")
    else
        ArrayClear("%1")
    end
    for w in string.gmatch (GetVariable("%1"), "%w+") do
        if GetVariable("IsKey") == "1" then
            SetVariable("ArrayKeyToUse", w)
            SetVariable("IsKey", 0)
        else
            SetVariable("IsKey", 1)
            ArraySet("%1", GetVariable("ArrayKeyToUse"), w)
        end -- if
    end -- for
end -- original if



The savevar alias does not require near the coding. I use REGEX of ^savevar (.+?)$ for the savevar alias.
CODE
if ArrayExists("%1") == false then
    Note("Array to save does not exist - Try another.")
else
SetVariable("%1", ArrayExport("%1", "|"))
Note(GetVariable("%1"))
end


If anyone more experienced then me know of a better way then feel free to elaborate.

What I do with these is Execute("savevar Dolls") in my quit alias and on the Password correct trigger I do Execute("loadvar Dolls"). I do this with the other arrays I use as well.
Trevize
Not bad. There's a simpler way to do that, I think.

SetVariable ("ArrayVar", ArrayExport ("Array", "| "))

ArrayImport ("Array", GetVariable ("ArrayVar") , "|")


On a side note, Arrays are something I've never used. Anything you can do in them, I believe you can do in Lua tables.
Dontarion
Yeah - I don't like how the arrays are setup in MUSH with me not being able to see them via gui. However, the things I use these aliases for are just a few in game triggers regarding antitheft, doll and fashions upkeep. Not something I really care to dedicate time to learning how to deal with tables.

I didn't see an ArrayImport function. Bleh.
Trevize
QUOTE (Dontarion @ Aug 18 2009, 08:24 AM) *
Yeah - I don't like how the arrays are setup in MUSH with me not being able to see them via gui. However, the things I use these aliases for are just a few in game triggers regarding antitheft, doll and fashions upkeep. Not something I really care to dedicate time to learning how to deal with tables.

I didn't see an ArrayImport function. Bleh.

I'd probably be faster and easier than figuring out Arrays. wink.gif Also, regarding making a graphical representation, you could easily do that with a few commands. Check out my antitheft plugin.
Dontarion
Yeah, I wrote my own output but I'd rather be able to see it in the MUSH variables gui listing.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.