Thread Tools Display Modes
10/30/14, 10:41 PM   #1
zireko
 
zireko's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 63
A Save Variable Question

This maybe and easy question but I've been playing around with a new code I wrote for my QuestCounter. My counter when double clicked will show 1, 2, 3, and so on. So someone can count how many quest they've done. I also have the mouse wheel when moved to reset it back to 0 and a slash command to hide it if you want. Now I have it where if you reloadui or logout it will remember where the location of the addon is and put it back so you don't have to keep moving it around. My question comes in on this example. If I have clicked my QuestCounter and have it saying Completed: 7 when I reload the ui it will set back to QuestCounter which is the original text. What I want it to do is if I logout and it says Completed: 7 when I log back in it will still say Completed: 7 . Here is my code below.

txt

Lua Code:
  1. ## APIVersion: 100009
  2. ## Title: |cFFFFB0QuestCounter|r 1.0
  3. ## Description: QuestCounter is just a simple counter that you can use to count the quest you've done.
  4. ## Author: |c00C000Zireko
  5. ## Version: 1.0
  6. ## SavedVariables: Cou_Variables
  7.  
  8. QuestCounter.xml
  9. QuestCounter.lua

xml

Lua Code:
  1. <GuiXml>
  2.     <Controls>
  3.         <TopLevelControl name="QuestCounter" clampedToScreen="true" mouseEnabled="true" movable="true" resizeToFitDescendents="true" hidden="false">
  4.             <Controls>
  5.                 <Label name="$(parent)Count" font="ZoFontBookScroll" color="CFDCBD" wrapMode="ELLIPSIS" verticalAlignment="CENTER" horizontalAlignment="CENTER" text="QuestCounter">
  6.                     <Anchor point="CENTER" />
  7.                 </Label>
  8.             </Controls>
  9.         </TopLevelControl>
  10.     </Controls>
  11. </GuiXml>

lua

Lua Code:
  1. --Still trying to figure out how to save the clicked count so on relog or reload it holds how many quest you've double clicked for.
  2.  
  3. local SV
  4. local defaults = {
  5.     ["Count"] = {
  6.         ["offsetx"] = 0,
  7.         ["offsety"] = 0,
  8.         ["point"] = CENTER,
  9.         ["relPoint"] = CENTER,
  10.         ["ClickedCount"] = 0,
  11.     },
  12. }
  13.  
  14. local ClickedCount = 0
  15.  
  16. local function ClickCount()
  17.     ClickedCount = ClickedCount + 1
  18.     QuestCounterCount:SetText("Completed: "..ClickedCount)
  19. end
  20.  
  21. local function ResetCount()
  22.     ClickedCount = 0
  23.     QuestCounterCount:SetText("QuestCounter")
  24. end
  25.  
  26.  
  27. local function OnMoveStop(self)
  28.     local valid, point, _, relPoint, offsetx, offsety = self:GetAnchor(0)
  29.     if valid then
  30.         SV.Count.point = point
  31.         SV.Count.relPoint = relPoint
  32.         SV.Count.offsetx = offsetx
  33.         SV.Count.offsety = offsety
  34.         SV.Count.ClickedCount = ClickedCount
  35.     end
  36. end
  37.  
  38. local function OnAddOnLoaded(eventCode, addon)
  39.     if addon == "QuestCounter" then
  40.         EVENT_MANAGER:UnregisterForEvent("QuestCounter", EVENT_ADD_ON_LOADED)
  41.  
  42.         SV = ZO_SavedVars:New("Cou_Variables", 2, nil, defaults)
  43.         QuestCounter:SetAnchor(SV.Count.point, nil, SV.Count.relPoint, SV.Count.offsetx, SV.Count.offsety)
  44.        
  45.         QuestCounter:SetHandler("OnMoveStop", OnMoveStop)
  46.         QuestCounter:SetHandler("OnMouseDoubleClick", ClickCount)
  47.         QuestCounter:SetHandler("OnMouseWheel", ResetCount)
  48.        
  49.         SLASH_COMMANDS["/qlc"] = function()
  50.             QuestCounter:ToggleHidden()
  51.         end
  52.  
  53.     end
  54. end
  55.  
  56. EVENT_MANAGER:RegisterForEvent("CountCounter", EVENT_ADD_ON_LOADED, OnAddOnLoaded)
  Reply With Quote
10/31/14, 03:23 AM   #2
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I didn't see this post until now or I would have answered here, but earlier I saw your statement about this problem on your addon page & sent you a PM about how to fix it.

Hope it helps.
  Reply With Quote
10/31/14, 06:12 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
If you want to store counter, you have to use saved variables - i.e. move your counter to saved variables table.

Just to show something different, I have also moved your code from XML to LUA.
Lua Code:
  1. local QuestCounter
  2. local SV
  3. local defaults = {
  4.     Count = {
  5.         offsetx = 0,
  6.         offsety = 0,
  7.         point = CENTER,
  8.         relPoint = CENTER,
  9.     },
  10.     ClickedCount = 0,
  11. }
  12.      
  13. local function ClickCount()
  14.     SV.ClickedCount = SV.ClickedCount + 1
  15.     QuestCounter.Count:SetText("Completed: " .. SV.ClickedCount)
  16. end
  17.      
  18. local function ResetCount()
  19.     SV.ClickedCount = 0
  20.     QuestCounter.Count:SetText("QuestCounter")
  21. end
  22.  
  23. local function OnMoveStop(self)
  24.     local valid, point, _, relPoint, offsetx, offsety = self:GetAnchor(0)
  25.     if valid then
  26.         SV.Count.point = point
  27.         SV.Count.relPoint = relPoint
  28.         SV.Count.offsetx = offsetx
  29.         SV.Count.offsety = offsety
  30.     end
  31. end
  32.  
  33. local function CreateAddonWindow()
  34.     --main window
  35.     QuestCounter = WINDOW_MANAGER:CreateTopLevelWindow()
  36.     QuestCounter:SetAnchor(SV.Count.point, nil, SV.Count.relPoint, SV.Count.offsetx, SV.Count.offsety)
  37.     QuestCounter:SetClampedToScreen(true)
  38.     QuestCounter:SetResizeToFitDescendents(true)
  39.     QuestCounter:SetMouseEnabled(true)
  40.     QuestCounter:SetMovable(true)
  41.     QuestCounter:SetHidden(false)
  42.            
  43.     --label
  44.     QuestCounter.Count = WINDOW_MANAGER:CreateControl(nil, QuestCounter, CT_LABEL)
  45.     QuestCounter.Count:SetAnchor(CENTER, QuestCounter, CENTER, 0, 0)
  46.     QuestCounter.Count:SetFont("ZoFontBookScroll")
  47.     QuestCounter.Count:SetColor(ZO_NORMAL_TEXT:UnpackRGBA())
  48.     QuestCounter.Count:SetWrapMode(TEXT_WRAP_MODE_ELLIPSIS)
  49.     QuestCounter.Count:SetVerticalAlignment(TEXT_ALIGN_CENTER)
  50.     QuestCounter.Count:SetHorizontalAlignment(TEXT_ALIGN_CENTER)
  51.     QuestCounter.Count:SetText("QuestCounter")
  52. end
  53.      
  54. local function OnAddOnLoaded(eventCode, addon)
  55.     if addon == "QuestCounter" then
  56.         --this event is no longer needed, unregister it
  57.         EVENT_MANAGER:UnregisterForEvent("QuestCounter", EVENT_ADD_ON_LOADED)
  58.  
  59.         --initialize saved variables
  60.         SV = ZO_SavedVars:New("Cou_Variables", 1, defaults)
  61.  
  62.         --this will create the same window as in your XML. There is just one difference - I made controls unnamed (there is no global reference to UI elements)
  63.         CreateAddonWindow()
  64.  
  65.         --mouse click handlers
  66.         QuestCounter:SetHandler("OnMoveStop", OnMoveStop)
  67.         QuestCounter:SetHandler("OnMouseDoubleClick", ClickCount)
  68.         QuestCounter:SetHandler("OnMouseWheel", ResetCount)
  69.  
  70.         --slash command
  71.         SLASH_COMMANDS["/qlc"] = function()
  72.             QuestCounter:ToggleHidden()
  73.         end
  74.     end
  75. end
  76.      
  77. EVENT_MANAGER:RegisterForEvent("QuestCounter", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

Last edited by Garkin : 10/31/14 at 06:46 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » A Save Variable Question


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