Thread Tools Display Modes
03-31-11, 01:07 PM   #1
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
SavedVariables Problem

im trying to save a single variable for my addon, and theres something wrong with my code, the variable doesnt exist everytime, is there something im missing

this is in my ToC file
Code:
## SavedVariablesPerCharacter: mLayouts
this is in my lua file
Code:
local frame = CreateFrame("FRAME", nil);
frame:RegisterEvent("ADDON_LOADED");
frame:RegisterEvent("PLAYER_LOGOUT");
local function loadvar(self, event, addon)
	if addon == "testaddon" then
                if mLayouts == nil then print("fail") end -- test function
		tempmLayouts = mLayouts or {}
	end
	if event == "PLAYER_LOGOUT" then
	   mLayouts = tempmLayouts; -- We've met; commit it to memory.
	end
end
frame:SetScript("OnEvent", loadvar);

Last edited by hairy_palms : 03-31-11 at 01:12 PM.
  Reply With Quote
03-31-11, 02:54 PM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Are you actually logging out?

I'm going with something like this (caution: Drycode)

lua Code:
  1. local frame = CreateFrame('Frame', nil, UIParent)
  2. frame:RegisterEvent('ADDON_LOADED')
  3. frame:SetScript('OnEvent', function(self, event, addon)
  4.      if addon ~= 'myAddon' then return end
  5.  
  6.      if not MySavedVar then
  7.          MySavedVar = {}
  8.      end
  9. end)
__________________
  Reply With Quote
03-31-11, 03:15 PM   #3
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
whether its a logout or just a /reload i get the same result, i tried your code just changing the names

Code:
local frame = CreateFrame('Frame', nil, UIParent)
frame:RegisterEvent('ADDON_LOADED')
frame:SetScript('OnEvent', function(self, event, addon)
     if addon ~= 'testaddon' then return end
 
     if not mLayouts then
         mLayouts = {}	
	print("still not saved")
     end
end)
"still not saved" is printed every login regardless

Last edited by hairy_palms : 03-31-11 at 03:18 PM.
  Reply With Quote
03-31-11, 06:29 PM   #4
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Perhaps there is something else wrong in your toc-file ?
Look at wow\logs\FrameXML.log ... perhaps there is more info.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
03-31-11, 07:14 PM   #5
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
1. Is your addon called "testaddon"? Capitalization matters, it should be exactly the same as your folder's name.

2. Did you ever declare mLayouts as a file-local variable? Savedvariables must be in global scope, if your addon defined a local one, your code would be referring to the local variable, and not the global one.

Without seeing the full contents of your files, it is difficult to guess where the problem might lie.
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
04-01-11, 06:48 AM   #6
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
What Xinhuan said. Using "## SavedVariables: Test" then in the addon doing: "local Test" would make "Test" refer to the local version in that lua file, hence nothing would be properly saved at all.
  Reply With Quote
04-01-11, 11:04 AM   #7
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
thanks for the help guys, i didnt change anything, but when i logged in today and the code i got from Mischback worked.
Code:
local frame = CreateFrame('Frame', nil, UIParent)
frame:RegisterEvent('ADDON_LOADED')
frame:SetScript('OnEvent', function(self, event, addon)
     if addon ~= 'SemoUI' then return end
 
     if not mLayouts then
         mLayouts = {}
     end
end)
  Reply With Quote
04-01-11, 12:05 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
When changing anything in the .toc file, a full game restart must take effect.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-03-11, 11:06 PM   #9
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Glad I could help!
__________________
  Reply With Quote
04-04-11, 04:41 AM   #10
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
One thing I noticed, sometimes the saved variables don't load when the variables event fires, it's said you should assume variables are fully loaded at addon_loaded event but my experience with some of my addons is that they don't -it's weird. :/

Just putting it out there, maybe you gotta use the variables loaded event to find out when the variable is loaded or not -for example declare it as nil at the top of the file and when it's not nil it means it's loaded.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SavedVariables Problem


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off