View Single Post
11/09/14, 06:36 AM   #1
brekal
Guest
Posts: n/a
UI Error - function expected instead of nil value

Hey,

I'm trying to make some Alchemy Addon to help me get an overview of the ingredients i have in my bag.
When logging into the game or reloading the UI it checks my backpack for some predefined Ingredients and saves the initial amount into a list.
As soon as a bagupdate happens, it checks if it is an ingredient and counts one to the existing value in the list.

The Function with the bagupdate works well but the function for getting the initial amount in my backpack throws an error.


The error is: function expected instead of nil value. The line is
Lua Code:
  1. LootManager:UpdateUI(name, count)

When I dump the two variables "name" and "count" they are defenitly not nil.

Here is the code of my lua-file:

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


Do you have any suggestions?

thanks in advance

Last edited by brekal : 11/09/14 at 12:47 PM.
  Reply With Quote