Originally Posted by Benalish
... if I write the print function outside this, the code doesn't work
Code:
local addon = CreateFrame("Frame", "MyAddon")
addon:RegisterEvent("ADDON_LOADED")
addon:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "MyAddon" then
-- Call the function to update your saved table:
MyAddonSavedVariables = CopyDefaults(MyDefaults, MyAddonSavedVariables)
-- Unregister this event, since there is no further use for it:
self:UnregisterEvent("ADDON_LOADED")
end
end)
print(MyAddonSavedVariables)
|
This is because the script you registered in
addon:SetScript() hasn't run yet. Look at the function there as a callback. It only runs when the frame receives any event that is registered to it. Since it's running the callback function when
ADDON_LOADED fires, it's running long after your
print() call. Try loading your addon, then typing
/dump MyAddonSavedVariables into chat.