Thread Tools Display Modes
08-10-19, 09:21 AM   #1
Sojiro84
Guest
Posts: n/a
Need help loading SavedVariable setting.

I searched around and I have tried a dozen things but somehow, I can't get it to work.
I can get the value 1 or 3 saved, but somewhere with reading it back, it goes wrong but I am unsure why.

Here is the AddOns code:

Code:
WorldMapFrame:SetScale(0.8)
Code:
WorldMapFrame.BlackoutFrame.Blackout:SetAlpha(0)

if SimpleMap == 1 then
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
elseif SimpleMap == 3 then
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
end


WorldMapFrame.ScrollContainer.GetCursorPosition = function(f)
    local x,y = MapCanvasScrollControllerMixin.GetCursorPosition(f);
    local s = WorldMapFrame:GetScale();
    return x/s, y/s;
end

local function SimpleMapCommands(msg, editbox)
  if msg == 'off' then
    print('SimpleMap fade has been turned off.')
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
    SimpleMap = 3
  elseif msg == 'on' then
    print("SimpleMap fade has been turned on.")
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
    SimpleMap = 1
  end
end


SLASH_SMFADE1 = '/smfade'

SlashCmdList["SMFADE"] = SimpleMapCommands


And here is the .toc.

Code:
## Interface: 11302
## Version: 1.1
## Title: SimpleMap
## Notes: Smaller worldmap and it fades the map when moving
## Author: Sojiro84
## Dependencies: Blizzard_WorldMap
## SavedVariables: SimpleMap

SimpleMap.lua
Code:



The savedvariable contrains either "SimpleMap = 1" or "SimpleMap = 3".

Somehow the following doesn't trigger:

Code:
if SimpleMap == 1 then
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
elseif SimpleMap == 3 then
    PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
end


I tried "AddOn Loaded" events and saying that variable "SimpleMap = SimpleMap" so that the value is loaded but nothing.

Clearly SimpleMap isn't being assigned with the SavedVariable value.

Can anyone help me?

It feels like the solution should be simple but I never made a WoW AddOn before so a bit difficult for me!

Last edited by Sojiro84 : 08-10-19 at 09:25 AM.
  Reply With Quote
08-10-19, 09:43 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
https://wow.gamepedia.com/Saving_var..._game_sessions

Saved variables are loaded after the addon code is executed
They cannot be accessed immediately, and will overwrite any "defaults" the addon may place in the global environment during its loading process.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-10-19, 09:49 AM   #3
Sojiro84
Guest
Posts: n/a
Yeah, I found that page and many others. I played around with those statements but it ended up breaking the whole addon or still not loading my value.


What am I missing?
  Reply With Quote
08-10-19, 10:02 AM   #4
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
The addon loading process loads the file(s), executes the stuff that is placed in the main code-flow and after that only events can trigger execution of your code.

Any code that is executed before ADDON_LOADED with the argument of your own addon cant access your SV.
You have to listen for this event. And only after this event occurs make sure it is fired for your addon and setup your stuff after that.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
08-10-19, 10:06 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Lua Code:
  1. WorldMapFrame.BlackoutFrame.Blackout:SetAlpha(0)
  2.  
  3. WorldMapFrame.ScrollContainer.GetCursorPosition = function(f)
  4.     local x,y = MapCanvasScrollControllerMixin.GetCursorPosition(f);
  5.     local s = WorldMapFrame:GetScale();
  6.     return x/s, y/s;
  7. end
  8.  
  9. local function SimpleMapCommands(msg, editbox)
  10.   if msg == 'off' then
  11.     print('SimpleMap fade has been turned off.')
  12.     PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
  13.     SimpleMap = 3
  14.   elseif msg == 'on' then
  15.     print("SimpleMap fade has been turned on.")
  16.     PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
  17.     SimpleMap = 1
  18.   end
  19. end
  20.  
  21.  
  22. SLASH_SMFADE1 = '/smfade'
  23.  
  24. SlashCmdList["SMFADE"] = SimpleMapCommands
  25.  
  26. local f = Createframe("Frame")
  27. f:SetScript("OnEvent", function(self, event, ...)
  28.     if SimpleMap == 1 then
  29.         PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
  30.     elseif SimpleMap == 3 then
  31.         PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
  32.     end
  33. end)
  34. f:RegisterEvent("PLAYER_LOGIN")
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-10-19 at 11:27 AM.
  Reply With Quote
08-10-19, 10:19 AM   #6
Sojiro84
Guest
Posts: n/a
Thank you both for the suggestions, but even with my whole script inside the addon_loaded event (with checking for my addon name), it still doesn't work.

Hell, my whole AddOn just doesn't work at all when I do it inside/after the addon_loaded event.


It was worth a shot.
  Reply With Quote
08-10-19, 11:16 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
SavedVariables are initially nil so if they require meaning other than that then you need to initialise them first time in.

PLAYER_LOGIN event
Lua Code:
  1. if not SimpleMap then
  2.     SimpleMap = 1
  3.     -- or SimpleMap = {}
  4.     -- or SimpleMap = Whatever
  5. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
08-10-19, 03:05 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Or, an edit to Fizzlemizz's code (that is more relevant to what you are learning):
Lua Code:
  1. local f = CreateFrame("Frame")  --oh, and there was a typo here
  2. f:SetScript("OnEvent", function(self, event, addon)
  3.     if addon == "YourAddonNameHere" then
  4.         if SimpleMap == 1 then
  5.             PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, .3, 3.0, .5)
  6.         elseif SimpleMap == 3 then
  7.             PlayerMovementFrameFader.AddDeferredFrame(WorldMapFrame, 1, 3.0, .5)
  8.         end
  9.     end
  10. end)
  11. f:RegisterEvent("ADDON_LOADED")

https://wow.gamepedia.com/AddOn_loading_process
__________________
"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
08-10-19, 04:12 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
I like PLAYER_LOGIN because you don't have to check for an addon name, it only fires once and that one time after all addons have loaded and before PLAYER_ENTERING_WORLD. Then again, I'm lazy
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
08-10-19, 04:20 PM   #10
Sojiro84
Guest
Posts: n/a
Thanks all for the help. I managed to get it working with the "PLAYER_LOGIN" event!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Need help loading SavedVariable setting.

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