Thread Tools Display Modes
11/11/14, 02:28 PM   #1
brekal
Guest
Posts: n/a
SavedVariables not working

Hey,

I'm getting quite desperate with my addon ;-)

I'm trying to save some simple Coordinates of an XML-element - but it doesn't create the file in the SavedVariables folder .....

Here is the Code:

Lua Code:
  1. LootManager = {}
  2. LootManager.name = "LootManager"
  3. LootManager.allCounts = {}
  4. LootManager.savedVars = {}
  5.  
  6. --
  7. --
  8.  
  9. function LootManager:OnAddOnLoad(event, addonName)
  10.     if addonName == LootManager.name then
  11.         LootManager:Initialize()
  12.    
  13.     end
  14. end
  15.  
  16. --
  17. --
  18.  
  19. function LootManager:Initialize()
  20.  
  21.     LootManager.allCounts["Kornblume"] = 0
  22.     LootManager.allCounts["Wiesenschaumkraut"] = 0
  23.     LootManager.allCounts["Wasserhyazinthe"] = 0
  24.    
  25.     local def = {
  26.         left = 100,
  27.         top = 200
  28.     }
  29.    
  30.     LootManager.savedVars = ZO_SavedVars:New("LootManagerTestVars", 1.0, nil, def)
  31.    
  32.     LootManager:RestorePosition()
  33. end
  34.  
  35. --
  36. --
  37.  
  38. function LootManager:SetPosition()
  39.     LootManager.savedVars.left = LootManagerWindow:GetLeft()
  40.     LootManager.savedVars.top = LootManagerWindow:GetTop()
  41. end
  42.  
  43. --
  44. --
  45.  
  46. function LootManager:RestorePosition()
  47.     local left = LootManager.savedVars.left
  48.     local top =  LootManager.savedVars.top
  49.    
  50.     LootManagerWindow:ClearAnchors()
  51.     LootManagerWindow:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
  52.    
  53. end
  54.  
  55. --
  56. --
  57.  
  58. function LootManager:GetBagOnInit()
  59.     local name
  60.     local itemName
  61.     local slotId
  62.     local count
  63.     local bagId = BAG_BACKPACK
  64.     local slots = GetBagSize(bagId)
  65.  
  66.     for i=0, slots - 1 do
  67.         slotId = i
  68.         itemName = GetItemName(bagId, slotId)
  69.         name = zo_strformat(SI_UNIT_NAME, itemName)
  70.         count = GetItemTotalCount(bagId, slotId)
  71.                
  72.         if name == "Wasserhyazinthe" then
  73.             LootManager.allCounts[name] = count
  74.             LootManager:UpdateUI(name, count)
  75.         end
  76.         if name == "Kornblume" then
  77.             LootManager.allCounts[name] = count
  78.             LootManager:UpdateUI(name, count)
  79.         end
  80.         if name == "Wiesenschaumkraut" then
  81.             LootManager.allCounts[name] = count
  82.             LootManager:UpdateUI(name, count)
  83.         end
  84.  
  85.     end
  86.  
  87.     LootManager:CheckMin()
  88.  
  89.     EVENT_MANAGER:UnregisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED)
  90. end
  91.  
  92. --
  93. -- When you put something in your bag it looks for ingredients and adds it to a list and updates the ui
  94.  
  95. function LootManager:BagUpdate( bagId,  slotId,  isNewItem,  itemSoundCategory,  updateReason)
  96.  
  97.     local itemName = GetItemName(bagId, slotId)
  98.     local name = zo_strformat(SI_UNIT_NAME, itemName)
  99.     local totalCount = GetItemTotalCount(bagId, slotId)
  100.  
  101.     if name == "Wasserhyazinthe" then
  102.         LootManager:UpdateUI(name, totalCount)
  103.         LootManager.allCounts[name] = totalCount
  104.     end
  105.    
  106.     if name == "Kornblume" then
  107.         LootManager:UpdateUI(name, totalCount)
  108.         LootManager.allCounts[name] = totalCount
  109.     end
  110.    
  111.     if name == "Wiesenschaumkraut" then
  112.         LootManager:UpdateUI(name, totalCount)
  113.         LootManager.allCounts[name] = totalCount
  114.     end
  115.    
  116.     LootManager:CheckMin()
  117. end
  118.  
  119. --
  120. -- Check if the values are not nil - otherwise math.min() throws an error
  121.  
  122. function LootManager:CheckMin()
  123.     local countMin
  124.    
  125.     if LootManager.allCounts["Wasserhyazinthe"] == nil or LootManager.allCounts["Kornblume"] == nil or LootManager.allCounts["Wiesenschaumkraut"] == nil then
  126.         countMin = 0
  127.     else
  128.         countMin = math.min(LootManager.allCounts["Wasserhyazinthe"], LootManager.allCounts["Kornblume"], LootManager.allCounts["Wiesenschaumkraut"])
  129.     end
  130.         LootManager:UpdateUI("Trank", countMin)
  131. end
  132.  
  133. --
  134. --
  135.  
  136. function LootManager:UpdateUI(labelName, value)
  137.     if labelName == "Wiesenschaumkraut" then
  138.         LootManagerWindowWiesenschaumkrautCount:SetText(value)
  139.     end
  140.     if labelName == "Kornblume" then
  141.         LootManagerWindowKornblumeCount:SetText(value)
  142.     end
  143.     if labelName == "Wasserhyazinthe" then
  144.         LootManagerWindowWasserhyazintheCount:SetText(value)
  145.     end
  146.     if labelName == "Trank" then
  147.         LootManagerWindowTrankCount:SetText(value)
  148.     end
  149. end
  150.  
  151.  
  152. --
  153. --
  154.  
  155. EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_ADD_ON_LOADED, LootManager.OnAddOnLoad)
  156. EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, LootManager.BagUpdate)
  157. EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED, LootManager.GetBagOnInit)

Lua Code:
  1. ## Title: LootManager
  2. ## Description: Wie viele Traenke kann ich brauen?
  3. ## Version: 1.0.0
  4. ## APIVersion: 100010
  5. ## SavedVariables: LootManagerTestVars
  6. ## Author: BreKal
  7.  
  8.  
  9. LootManager.xml
  10. LootManager.lua

I did some debugging and found out that first of all it does not Initialize the LootManager.savedVars with the def values.

I can save the actual position of the XML-Element to LootManager.savedVars and can then read them from LootManager.savedVars. So actually it is saving the values to it - but it does simply not create the file. So when i reloadui or relog, the values reset.

Can you tell me why it is not creating the file?

thanks in advance
  Reply With Quote
11/11/14, 08:05 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by brekal View Post
Lua Code:
  1. function LootManager:OnAddOnLoad(event, addonName)
If you define a method using : instead of . it will have a hidden first argument self, i.e. the above definition is just syntax sugar for (equal to):
Lua Code:
  1. function LootManager.OnAddOnLoad(self, event, addonName)

EVENT_MANGER is calling it with two arguments, therefore in your handler addonName is always nil.

It's common to define the OnLoad handler as a local function onLoad(event, addonName), you won't need to call it from any other place, so it doesn't have to be among your addon's exposed methods.
  Reply With Quote
11/12/14, 03:36 AM   #3
brekal
Guest
Posts: n/a
thank you very much merlight.

And again I learned so much from you

Now it works. It stores the values correctly and creates the file.

I'm really sorry to keep you busy with my noob questions/errors
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » SavedVariables not working


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