Thread Tools Display Modes
02/22/15, 10:04 AM   #1
papaoscar90
Join Date: Feb 2015
Posts: 5
savedVariables, position not saving?

I have completed the tutorials on the wiki, and am not practicing making them from scratch without looking at the tutorials (just my notes and references). I got my addon to display the d("Entering") and d("Exiting") combat as well as show the popup window "ENGAGED" in red. Now I am trying to figure out the savedVariables but I am running into a bit of trouble. I opened up the savedVariables tutorial and pulled out as much info as I could from it, but my addon still doesn't want to remember where it was on reload. Can somebody take a look please?

Addon Structure
Addons/PhilsCombatIndicator/
->PhilsCombatIndicator.txt
->PhilsCombatIndicator.xml
->PhilsCombatIndicator.lua

Text File
Code:
## Title: Phils Combat Indicator
## Description: Displays Combat State
## APIVersion: 100010
## Version: .1
## SaveVariables: PhilsCombatIndicatorVariables

PhilsCombatIndicator.xml
PhilsCombatIndicator.lua
Xml File
Code:
<GuiXml>
	<Controls>
		<TopLevelControl name="PhilsCombatIndicatorWindow" movable="true" mouseEnabled="true" hidden="false">
			<Dimensions x="300" y="50"/>
			<Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="CENTER" offsetX="0" offsetY="0"/>
			<OnMoveStop>
				PhilsCombatIndicator.SaveLoc()
			</OnMoveStop>
		<Controls>
			<Label name="$(parent)Label" width="300" height="50" font="ZoFontWinH1" inheritAlpha="true" color="FF0000"
			wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="ENGAGED">
				<Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT"/>
			</Label>
		</Controls>
		
		</TopLevelControl>
	</Controls>
</GuiXml>
Lua File
Lua Code:
  1. PhilsCombatIndicator = {}
  2. PhilsCombatIndicator.name = "PhilsCombatIndicator"
  3. PhilsCombatIndicator.Default = {
  4.         offsetX = 20,
  5.         offsetY = 75
  6. }
  7.  
  8. function PhilsCombatIndicator.SaveLoc()
  9.     PhilsCombatIndicator.savedVariables.offsetX = PhilsCombatIndicatorWindowLabel:GetLeft()
  10.     PhilsCombatIndicator.savedVariables.offsetY = PhilsCombatIndicatorWindowLabel:GetTop()
  11. end
  12.  
  13. function PhilsCombatIndicator.OnCombat(event, inCombat)
  14.     d("OnCombat Called")
  15.     if inCombat then
  16.         d("Entering Combat")
  17.         PhilsCombatIndicatorWindow:SetHidden(false)
  18.         else
  19.         d("Leaving Combat")
  20.         PhilsCombatIndicatorWindow:SetHidden(true)
  21.     end
  22.     d("OnCombat Ending")
  23. end
  24.  
  25.  
  26. function PhilsCombatIndicator.Initialize(event, addonName)
  27.     if addonName == PhilsCombatIndicator.name then
  28.         PhilsCombatIndicator.savedVariables = ZO_SavedVars:New("PhilsCombatIndicatorVariables", 1, nil, PhilsCombatIndicator.Default)
  29.         EVENT_MANAGER:RegisterForEvent(PhilsCombatIndicator.name, EVENT_PLAYER_COMBAT_STATE, PhilsCombatIndicator.OnCombat)
  30.         PhilsCombatIndicatorWindow:ClearAnchors()
  31.         PhilsCombatIndicatorWindow:SetAnchor(TOPLEFT, GuiRoot, CENTER, PhilsCombatIndicator.savedVariables.offsetX, PhilsCombatIndicator.savedVariables.offsetY)
  32.         EVENT_MANAGER:UnregisterForEvent(PhilsCombatIndicator.name, EVENT_ADD_ON_LOADED)
  33.     else
  34.         return
  35.     end
  36. end
  37.  
  38. EVENT_MANAGER:RegisterForEvent(PhilsCombatIndicator.name, EVENT_ADD_ON_LOADED, PhilsCombatIndicator.Initialize)
  Reply With Quote
02/22/15, 10:11 AM   #2
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Code:
## Title: Phils Combat Indicator
## Description: Displays Combat State
## APIVersion: 100010
## Version: .1
## SavedVariables: PhilsCombatIndicatorVariables

PhilsCombatIndicator.xml
PhilsCombatIndicator.lua
Small typo: There is a "d" missing: "SavedVariables", not "SaveVariables".

Last edited by votan : 02/22/15 at 10:19 AM.
  Reply With Quote
02/22/15, 11:27 AM   #3
papaoscar90
Join Date: Feb 2015
Posts: 5
Thanks! Now when I run it, the "ENGAGED" always appears on the far right side of the screen, about 2/3 way down mostly off the screen. No matter where I drag it to, on /reloadui it goes back to the same spot.

edit: I may have figured it out. I turn on some d() displaying the position values. Then I realized I may be making those values from the center of the screen not the topleft. Checking

edit2: This was indeed the problem. The SetAnchor was making the CENTER of the screen the starting point. Changed it to TOPLEFT and it is working as intended.

Last edited by papaoscar90 : 02/22/15 at 11:32 AM.
  Reply With Quote
02/22/15, 01:13 PM   #4
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
You can also add the attribute clampedToScreen="true"
Lua Code:
  1. <TopLevelControl name="PhilsCombatIndicatorWindow" movable="true" mouseEnabled="true" hidden="false" clampedToScreen="true" >

If you want to prevent a control from going off of the screen.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » savedVariables, position not saving?


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