WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Strangeness with SavedVariables and SavedVariablePerCharacter (https://www.wowinterface.com/forums/showthread.php?t=46794)

Yup 07-09-13 04:54 PM

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. :)

Fizzlemizz 07-09-13 06:27 PM

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?

Yup 07-09-13 06:30 PM

There was just an update to WoW and that seems to have fixed my problem. Thanks for the help, though!

Vlad 07-10-13 04:16 AM

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.

Yup 07-10-13 05:45 AM

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)

Vlad 07-10-13 07:24 AM

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)


Rainrider 07-10-13 07:38 AM

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.

Yup 07-10-13 08:11 AM

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.

Resike 07-10-13 09:24 AM

Quote:

Originally Posted by Yup (Post 281015)
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.

Yup 07-10-13 09:53 AM

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.

Resike 07-10-13 12:39 PM

Quote:

Originally Posted by Yup (Post 281018)
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.


All times are GMT -6. The time now is 03:31 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI