Thread Tools Display Modes
05/03/14, 03:14 PM   #1
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Help with savedVars and movable frames

I've tried finding the solution to my issue using these threads already:
http://www.esoui.com/forums/showthread.php?t=1173
http://wiki.esoui.com/AddOn_Quick_Questions

Basically I am trying to save a movable frame's location across logouts and reloaduis using a saved variables file.

My code looks like this:

In MyAddon.txt
Code:
## SavedVariables: Postmaster_SavedVariables

Lua Code:
  1. -- save frame location after moving
  2. function pOnMoveStop()
  3.   local name = Postmaster:GetName()
  4.   local left = Postmaster:GetLeft()
  5.   local top = Postmaster:GetTop()
  6.  
  7.   if name == "" or name == nil then return end --debug line
  8.   d("Position of "..name.." frame saved to "..left.."X, "..top.."Y.") --debug line
  9.   savedVars.frameX = left
  10.   savedVars.frameY = top
  11.  
  12. end
  13.  
  14. -- init default values
  15. local defaults =
  16. {
  17.   frameX = 100,
  18.   frameY = 200,
  19. }
  20.  
  21. -- Initalizing the addon
  22. local function pInitialize( eventCode, addOnName )
  23.  
  24.   if ( addOnName ~= "Postmaster" ) then return end
  25.  
  26.  
  27.   -- Get savedVars or set defaults
  28.   savedVars = ZO_SavedVars:NewAccountWide("Postmaster_SavedVariables", Postmaster.version, nil, defaults)
  29.  
  30.   --Postmaster:ClearAnchors()
  31.   Postmaster:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, savedVars.frameX, savedVars.frameY)
  32. end

The issue, is that the default values will overwrite the saved values from the OnMoveStop function when I reloadui. I do not know how to initialize the saved Vars file without including the default values to avoid having a nil value error.

Last edited by Zierk : 05/03/14 at 03:44 PM. Reason: correct typo
  Reply With Quote
05/03/14, 03:19 PM   #2
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 135
I think that the problem is that your savedVars variable is local to the initialize function.
  Reply With Quote
05/03/14, 03:24 PM   #3
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
I just editted that, it wasn't suppose to be local. even with savedVars not being local to initialize, the default values still override the values set by OnMoveStop.
  Reply With Quote
05/03/14, 03:31 PM   #4
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Where is "MyAddon_SavedVariables" in your code?
  Reply With Quote
05/03/14, 03:43 PM   #5
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Originally Posted by Iyanga View Post
Where is "MyAddon_SavedVariables" in your code?
## SavedVariables: Postmaster_SavedVariables
is located in Postmaster.txt in the root addon folder, then "Postmaster_SavedVariables" is referenced in the ZO_SavedVars call. I successfully generate the Postmaster.lua file in the SavedVariables folder inside the ESO>live folder, its just the values get overwritten.

Here is my saved variables files after I move the frame
Code:
Postmaster_SavedVariables =
{
    ["Default"] = 
    {
        ["@Zierk"] = 
        {
            ["$AccountWide"] = 
            {
                ["frameX"] = 449,
                ["frameY"] = 453,
            },
        },
    },
}
Then after a reloadui:
Code:
Postmaster_SavedVariables =
{
    ["Default"] = 
    {
        ["@Zierk"] = 
        {
            ["$AccountWide"] = 
            {
                ["frameX"] = 100,
                ["frameY"] = 200,
            },
        },
    },
}
NOTE:
"MyAddon_SavedVariables" was a mis-copy/paste into the post, in the addon code it is "Postmaster_SavedVariables".

Last edited by Zierk : 05/03/14 at 03:48 PM.
  Reply With Quote
05/03/14, 03:58 PM   #6
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
And Postmaster.version equals what?
  Reply With Quote
05/03/14, 04:17 PM   #7
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Originally Posted by Iyanga View Post
And Postmaster.version equals what?
Postmaster = {}

Postmaster.name = "Postmaster"
Postmaster.version = 1.0
Postmaster.author = '@Zierk'
  Reply With Quote
05/03/14, 07:25 PM   #8
Zierk
 
Zierk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 10
Seems to be working now, I redid my naming convention and changed Postmaster = {} to PM = {} and changed all the tables and variables accordingly. Strange, but it works just fine now. Thanks for the quick replies to everyone who replied!
  Reply With Quote
05/03/14, 07:27 PM   #9
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Ah, you used the same name as your addon itself. Must have confused the hell out of it.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Help with savedVars and movable frames

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