View Single Post
12-11-12, 01:49 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Benalish View Post
... 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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-11-12 at 01:52 PM.
  Reply With Quote