WoW:Saving variables between game sessions: Difference between revisions

m
Line 32: Line 32:
<div style="border:solid 1px; padding:1em;background:#222;color:#ccc;"><div>
<div style="border:solid 1px; padding:1em;background:#222;color:#ccc;"><div>
=== The RegisterForSave function (Do not use this) ===
=== The RegisterForSave function (Do not use this) ===
 
'''THIS FUNCTION IS NOW RESTRICTED'''
***THIS FUNCTION IS NOW RESTRICTED***
This function is now restricted to Blizzard-signed addons, and addons which depend on it will no longer work.
This function is now restricted to Blizzard-signed addons, and addons which depend on it will no longer work.


'''IMPORTANT:''' This information is really for reference only, you almost never want to use this. Use SavedVariables instead.
'''IMPORTANT:''' This information is really for reference only, you can not access this functionality from outside Blizzard signed AddOns. Use SavedVariables instead.


LUA code can explicitly request that a variable be saved by calling the [[API RegisterForSave|RegisterForSave("varName")]] function with the variable name that should be saved. That variable then becomes flagged for saving at the end of the session.  It's important to note that since this is an active process, the variable will only be saved if it is registered during a session, so compilation execution failures that prevent the call from being made will end up without the variable being flagged.
LUA code can explicitly request that a variable be saved by calling the [[API RegisterForSave|RegisterForSave("varName")]] function with the variable name that should be saved. That variable then becomes flagged for saving at the end of the session.  It's important to note that since this is an active process, the variable will only be saved if it is registered during a session, so compilation execution failures that prevent the call from being made will end up without the variable being flagged.
Line 83: Line 82:
Not all Lua constructs can be saved. For example, inline functions.
Not all Lua constructs can be saved. For example, inline functions.


    function f()
function f()
        data = 1
  data = 1
        local function g()
  local function g()
            -- code block
    -- code block
        end
  end
        return { data, g }
  return { data, g }
    end
end
 
    savedVar = f()  -- will fail to save g
savedVar = f()  -- will fail to save g


[[Category: HOWTOs|Save Variables Between Game Sessions]]
[[Category: HOWTOs|Save Variables Between Game Sessions]]