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:
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:
LootManager = {}
LootManager.name = "LootManager"
LootManager.allCounts = {}
--
--
function LootManager:Initialize()
LootManager.allCounts["Kornblume"] = 0
LootManager.allCounts["Wiesenschaumkraut"] = 0
LootManager.allCounts["Wasserhyazinthe"] = 0
end
--
--
function LootManager:OnAddOnLoad(event, addonName)
if addonName == LootManager.name then
LootManager:Initialize()
end
end
--
--
function LootManager:GetBagOnInit()
local name
local itemName
local slotId
local count
local bagId = BAG_BACKPACK
local slots = GetBagSize(bagId)
for i=0, slots - 1 do
slotId = i
itemName = GetItemName(bagId, slotId)
name = zo_strformat(SI_UNIT_NAME, itemName)
count = GetItemTotalCount(bagId, slotId)
if name == "Wasserhyazinthe" then
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
if name == "Kornblume" then
d(name)
d(count)
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
if name == "Wiesenschaumkraut" then
LootManager.allCounts[name] = count
LootManager:UpdateUI(name, count)
end
end
LootManager:CheckMin()
EVENT_MANAGER:UnregisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED)
end
--
-- When you put something in your bag it looks for ingredients and adds it to a list and updates the ui
function LootManager:BagUpdate( bagId, slotId, isNewItem, itemSoundCategory, updateReason)
local itemName = GetItemName(bagId, slotId)
local name = zo_strformat(SI_UNIT_NAME, itemName)
local totalCount = GetItemTotalCount(bagId, slotId)
if name == "Wasserhyazinthe" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
if name == "Kornblume" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
if name == "Wiesenschaumkraut" then
LootManager:UpdateUI(name, totalCount)
LootManager.allCounts[name] = totalCount
end
LootManager:CheckMin()
end
--
-- Check if the values are not nil - otherwise math.min() throws an error
function LootManager:CheckMin()
local countMin
if LootManager.allCounts["Wasserhyazinthe"] == nil or LootManager.allCounts["Kornblume"] == nil or LootManager.allCounts["Wiesenschaumkraut"] == nil then
countMin = 0
else
countMin = math.min(LootManager.allCounts["Wasserhyazinthe"], LootManager.allCounts["Kornblume"], LootManager.allCounts["Wiesenschaumkraut"])
end
LootManager:UpdateUI("Trank", countMin)
end
--
--
function LootManager:UpdateUI(labelName, value)
if labelName == "Wiesenschaumkraut" then
LootManagerWindowWiesenschaumkrautCount:SetText(value)
end
if labelName == "Kornblume" then
LootManagerWindowKornblumeCount:SetText(value)
end
if labelName == "Wasserhyazinthe" then
LootManagerWindowWasserhyazintheCount:SetText(value)
end
if labelName == "Trank" then
LootManagerWindowTrankCount:SetText(value)
end
end
--
--
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_ADD_ON_LOADED, LootManager.OnAddOnLoad)
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, LootManager.BagUpdate)
EVENT_MANAGER:RegisterForEvent(LootManager.name, EVENT_PLAYER_ACTIVATED, LootManager.GetBagOnInit)
Do you have any suggestions?
thanks in advance