Hey, I'm the author of the Reagent Restocker addon, and I'm trying to add guild bank support to my addon.
Currently, Reagent Restocker makes several calls to GetContainerItemLink and GetContainerItemInfo. However, all of that changes when I want it to access the guild bank.
When the guild bank is being accessed, it needs to use GetGuildBankItemLink and GetGuildBankItemInfo for items in the guild bank.
Problem is, I'm unsure of how to do this cleanly. I started putting in a lot of if...else..end statements, but it just makes the code a lot more complex and more difficult to work with, and has to be done pretty much anywhere where I need choose between a guild bank function and the regular function.
Is there a way to cleanly use these API calls without making my code a mess?
Couldn't you wrap the calls in a local function and do the logic there? Then at least you wouldn't have lots of ifs running in the code.
You could either do those if-statements you mentioned or if you can tell for sure when a player is or isn't at the guild bank you could pass a boolean to the function.
Code:
local function RetrieveInfo(gbank)
if gbank then
-- use GetGuildBank*
else
-- use GetContainer*
end
end
function ProcessInfo(link, info)
end
function RetrieveBagOrBankInfo()
local link = GetContainerItemLink()
local info = { GetContainerItemInfo() }
ProcessInfo(link, info)
end
function RetrieveGuildBankInfo()
local link = GetGuildBankItemLink()
local info = { GetGuildBankItemInfo() }
ProcessInfo(link, info)
end
I would keep each separate so it is clear what api's are being called. This code is more readable imho.