View Single Post
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