Thread Tools Display Modes
07-09-13, 04:54 PM   #1
Yup
A Murloc Raider
 
Yup's Avatar
Join Date: Jul 2013
Posts: 8
Strangeness with SavedVariables and SavedVariablePerCharacter

I seem to be having a problem where I can't access any saved variables from my own AddOns. It works with others, like Recount, but when I try to access and save my own, it seems to just ignore SavedVariables and SavedVariablesPerCharacter.

And example would be the simple WhyHelloThar tutorial AddOn from this MMO-Champion thread, using the code from the Alternate Method:

WhyHelloThar.toc
Code:
## Interface: 50300
## Title: WhyHelloThar
## Author: SomeoneElse
## Dependencies: Ace3
## OptDeps: BugSack, !Swatter
## SavedVariables: mySavedVar
## SavedVariablesPerCharacter: charVar

WhyHelloThar.lua
WhyHelloThar.lua
Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2.  
  3. EventFrame:RegisterEvent("PLAYER_LOGIN")
  4. EventFrame:SetScript("OnEvent", function(self,event,...)
  5.     if type(charVar) ~= "number" then
  6.         charVar = 1
  7.         ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  I do believe this is the first time we've met.  Nice to meet you!")
  8.     else
  9.         if charVar == 1 then
  10.             ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  How nice to see you again!  I do believe I've seen you once before.")
  11.         else
  12.             ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  How nice to see you again!  I do believe I've seen you " .. charVar .. " times before.")
  13.         end
  14.         charVar = charVar + 1
  15.     end
  16. end)

It was working for a while then it just gave out. It works during the session, starting over again at an empty variable, but will not save over sessions or load from previous ones. I'm extremely new to AddOn development so any advice would be appreciated.

Last edited by Yup : 07-09-13 at 04:55 PM. Reason: Added Information
  Reply With Quote
07-09-13, 06:27 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Have you checked to see if the YourAddon.lua file is being created in the WTF\
Account\[AccountName]\SavedVariables and WTF\
Account\[AccountName]\[Realm]\[Character]\SavedVariables folders and if so, what does it contain?

Last edited by Fizzlemizz : 07-09-13 at 06:32 PM.
  Reply With Quote
07-09-13, 06:30 PM   #3
Yup
A Murloc Raider
 
Yup's Avatar
Join Date: Jul 2013
Posts: 8
There was just an update to WoW and that seems to have fixed my problem. Thanks for the help, though!
  Reply With Quote
07-10-13, 04:16 AM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
It's not so strange, because when not monitoring ADDON_LOADED the variables might end up in a situation where PLAYER_LOGIN fires and the variables are not yet initialized.
__________________
Profile: Curse | Wowhead
  Reply With Quote
07-10-13, 05:45 AM   #5
Yup
A Murloc Raider
 
Yup's Avatar
Join Date: Jul 2013
Posts: 8
Well, I had modified it to check for ADDON_LOADED, and that's what I'm going to be doing with my own project. I just posted the original because it was directly from a tutorial that had always worked for me anyway. And no, even with checking for ADDON_LOADED it didn't work. It doesn't matter anyway, the update seems to have fixed things, though I don't know why.

Something analogous to what I modified it to:
Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2.  
  3. EventFrame:RegisterEvent("ADDON_LOADED")
  4. EventFrame:SetScript("OnEvent", function(self,event,name,...)
  5.     if name == "WhyHelloThar" then
  6.         if type(charVar) ~= "number" then
  7.             charVar = 1
  8.             ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  I do believe this is the first time we've met.  Nice to meet you!")
  9.         else
  10.             if charVar == 1 then
  11.                 ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  How nice to see you again!  I do believe I've seen you once before.")
  12.             else
  13.                 ChatFrame1:AddMessage('WhyHelloThar ' .. UnitName("Player") .. ".  How nice to see you again!  I do believe I've seen you " .. charVar .. " times before.")
  14.             end
  15.             charVar = charVar + 1
  16.         end
  17.     end
  18. end)
  Reply With Quote
07-10-13, 07:24 AM   #6
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
A small rewrite, take what you wish from the code:
Code:
local addonName = ...

local function th(i)
	if i > 3 and i < 21 then
		return i .. "th"
	end
	local n = i % 10
	if n == 1 then
		return i .. "st"
	elseif n == 2 then
		return i .. "nd"
	elseif n == 3 then
		return i .. "rd"
	end
	return i .. "th"
end

local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")

frame:SetScript("OnEvent", function(self, event, ...)
	if event == "ADDON_LOADED" and ... == addonName then
		-- mySavedVar and charVar should be loaded now - but the names are too vague and other addons might overrite your values, if the other addons are badly coded.
		if type(charVar) ~= "number" then
			charVar = 0
		end
		charVar = charVar + 1
		if charVar == 1 then
			print("Hello " .. UnitName("player") .. ", it's nice to meet you!")
		else
			print("Hello again " .. UnitName("player") .. ", this is our " .. th(charVar) .. " meeting.")
		end
	end
end)
__________________
Profile: Curse | Wowhead
  Reply With Quote
07-10-13, 07:38 AM   #7
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Your addon loaded before you see the ui, that's why you didn't see the message it prints. Probably the same reason when you used PLAYER_LOGIN. That's just in case you consider it working only when you see the message printed.
  Reply With Quote
07-10-13, 08:11 AM   #8
Yup
A Murloc Raider
 
Yup's Avatar
Join Date: Jul 2013
Posts: 8
The message would display, but only the one for the non-initialized variable. It would just display, "WhyHelloThar Yup. I do believe this is the first time we've met. Nice to meet you!" over and over again.
  Reply With Quote
07-10-13, 09:24 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Yup View Post
The message would display, but only the one for the non-initialized variable. It would just display, "WhyHelloThar Yup. I do believe this is the first time we've met. Nice to meet you!" over and over again.
Do you have proper access to write in that folder where is your wow installed? Could be the issue if it's in the program files.
  Reply With Quote
07-10-13, 09:53 AM   #10
Yup
A Murloc Raider
 
Yup's Avatar
Join Date: Jul 2013
Posts: 8
I do. But again, everything is working properly now. There was something in the last update that fixed it for me. Don't know what it was, as it wasn't documented. I'm also guessing what may have happened is that I somehow broke my installation when messing with AddOn files and when the Launcher updated WoW it also repaired it.

Last edited by Yup : 07-10-13 at 09:55 AM.
  Reply With Quote
07-10-13, 12:39 PM   #11
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Yup View Post
I do. But again, everything is working properly now. There was something in the last update that fixed it for me. Don't know what it was, as it wasn't documented. I'm also guessing what may have happened is that I somehow broke my installation when messing with AddOn files and when the Launcher updated WoW it also repaired it.
I don't think the laucher does anything with the addons, or savedvars, nor the framexml got updated, most likely a client restart can fix things like that.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Strangeness with SavedVariables and SavedVariablePerCharacter

Thread Tools
Display Modes

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