Thread Tools Display Modes
02-17-14, 07:18 AM   #1
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
Fetching items from the GuildBank

I need some help! The first function (code fragment) fails to fetch an item from the GuildBank. It is modeled after the second function (code fragment) which succeeds in fetching an item from the (character) Bank.

The third code segment is the output of the failing function and the fourth is the output of the working function. There is one stack of the item in the GuildBank and two stacks of the item in the bank. Other than that, the two outputs appear to be functionally equivalent (to me). This is why I'm stumped!

These code fragments are from Skillet (http://www.wowinterface.com/download...1-Skillet.html) and can be downloaded in its current alpha state (complete with bugs) at http://www.wowinterface.com/downloads/info22757.html.

Code:
local function getItemFromGuildBank(itemID, bag, slot, count)
	print("getItemFromGuildBank(",itemID,", ", bag,", ", slot,", ", count,")")
	ClearCursor()
	local _, available = GetGuildBankItemInfo(bag, slot)
	local link = GetGuildBankItemLink(bag, slot)
	local num_moved = 0

	if available == 1 or count >= available then
		print("PickupGuildBankItem(",bag,", ", slot,")")
		PickupGuildBankItem(bag, slot)
		num_moved = available
	else
		print("SplitGuildBankItem(",bag,", ", slot,", ", count,")")
		SplitGuildBankItem(bag, slot, count)
		num_moved = count
	end

	local type, data, subType, subData = GetCursorInfo()
	print("type=",type,", data=",data,", subType=",subType)

	local tobag = findBagForItem(itemID, num_moved)
	print("tobag=",tobag,", findBagForItem(",itemID,", ", num_moved,")")

	if not tobag then
		Skillet:Print(L["Could not find bag space for"] .. ": " .. link)
		return 0
	end

	if tobag == 0 then
		print("PutItemInBackpack()")
		PutItemInBackpack()
	else
		print("PutItemInBag(",ContainerIDToInventoryID(tobag),")")
		PutItemInBag(ContainerIDToInventoryID(tobag))
	end

	return num_moved
end
Code:
local function getItemFromBank(itemID, bag, slot, count)
	print("getItemFromBank(",itemID,", ", bag,", ", slot,", ", count,")")
	ClearCursor()
	local _, available = GetContainerItemInfo(bag, slot)
	local link = GetContainerItemLink(bag, slot)
	local num_moved = 0

	if available == 1 or count >= available then
		print("PickupContainerItem(",bag,", ", slot,")")
		PickupContainerItem(bag, slot)
		num_moved = available
	else
		print("SplitContainerItem(",bag,", ", slot,", ", count,")")
		SplitContainerItem(bag, slot, count)
		num_moved = count
	end

	local type, data, subType, subData = GetCursorInfo()
	print("type=",type,", data=",data,", subType=",subType)

	local tobag = findBagForItem(itemID, num_moved)
	print("tobag=",tobag,", findBagForItem(",itemID,", ", num_moved,")")

	if not tobag then
		Skillet:Print(L["Could not find bag space for"] .. ": " .. link)
		return 0
	end

	if tobag == 0 then
		print("PutItemInBackpack()")
		PutItemInBackpack()
	else
		print("PutItemInBag(",ContainerIDToInventoryID(tobag),")")
		PutItemInBag(ContainerIDToInventoryID(tobag))
	end

	return num_moved
end
Code:
GUILDBANKFRAME_OPENED
CURSOR_UPDATE - type= nil , data= nil , subType= nil
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
GUILDBANKBAGSLOTS_CHANGED
indexGuildBank size=  546
getItemFromGuildBank( 76142 ,  1 ,  20 ,  1 )
CURSOR_UPDATE - type= nil , data= nil , subType= nil
SplitGuildBankItem( 1 ,  20 ,  1 )
CURSOR_UPDATE - type= item , data= 76142 , subType= [Sun's Radiance]
type= item , data= 76142 , subType= [Sun's Radiance]
tobag= 0 , findBagForItem( 76142 ,  1 )
PutItemInBackpack()
CURSOR_UPDATE - type= nil , data= nil , subType= nil
GUILDBANKFRAME_CLOSED
Code:
BANKFRAME_OPENED
CURSOR_UPDATE - type= nil , data= nil , subType= nil
indexBank size=  218
getItemFromBank( 76142 ,  10 ,  2 ,  1 )
CURSOR_UPDATE - type= nil , data= nil , subType= nil
SplitContainerItem( 10 ,  2 ,  1 )
CURSOR_UPDATE - type= item , data= 76142 , subType= [Sun's Radiance]
type= item , data= 76142 , subType= [Sun's Radiance]
tobag= 0 , findBagForItem( 76142 ,  1 )
PutItemInBackpack()
CURSOR_UPDATE - type= nil , data= nil , subType= nil
getItemFromBank( 76142 ,  10 ,  6 ,  0 )
CURSOR_UPDATE - type= nil , data= nil , subType= nil
SplitContainerItem( 10 ,  6 ,  0 )
type= nil , data= nil , subType= nil
tobag= 0 , findBagForItem( 76142 ,  0 )
PutItemInBackpack()
CURSOR_UPDATE - type= nil , data= nil , subType= nil
BANKFRAME_CLOSED
  Reply With Quote
02-17-14, 08:28 AM   #2
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
If you bang your head against the wall enough times, the answer will come to you!

It turns out that PutItemInBackpack and PutItemInBag don't work with the GuildBank. You have to use PickupContainerItem to put the item(s) into the character's bags (AutoStoreGuildBankItem also works but moves the whole stack). Here's the working version:

Code:
local function getItemFromGuildBank(itemID, bag, slot, count)
	print("getItemFromGuildBank(",itemID,", ", bag,", ", slot,", ", count,")")
	ClearCursor()
	local _, available = GetGuildBankItemInfo(bag, slot)
	local link = GetGuildBankItemLink(bag, slot)
	local num_moved = 0

	if available == 1 or count >= available then
		print("PickupGuildBankItem(",bag,", ", slot,")")
		PickupGuildBankItem(bag, slot)
		num_moved = available
	else
		print("SplitGuildBankItem(",bag,", ", slot,", ", count,")")
		SplitGuildBankItem(bag, slot, count)
		num_moved = count
	end

	local type, data, subType, subData = GetCursorInfo()
	print("type=",type,", data=",data,", subType=",subType)

	local tobag, toslot = findBagForItem(itemID, num_moved)
	print("tobag=",tobag,", toslot=",toslot,", findBagForItem(",itemID,", ", num_moved,")")

	if not tobag then
		Skillet:Print(L["Could not find bag space for"] .. ": " .. link)
		return 0
	end

	PickupContainerItem(tobag, toslot) -- actually puts the item in the bag
	return num_moved
end
  Reply With Quote
02-17-14, 08:30 AM   #3
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
I'll update my version of Skillet after I chase out a few more (unrelated) bugs.
  Reply With Quote
02-17-14, 10:18 AM   #4
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
(I love talking to myself)

I've hit another snag, the function that calls getItemFromGuildBank is processing a list of items needed. If there is only one item on the list, getItemFromGuildBank succeeds. If there are multiple items on the list, the first call succeeds and subsequent calls fail (with "Internal guild error." printed in chat).

I think I know what the problem is, but I don't know the best way to fix it. I need to wait for the move to finish between successive items. I think the logic for this would best be implemented as a coroutine but I can't find an example simple enough for me to understand. Can anyone help?

I've searched for an addon that moves items out of (or into) the GuildBank to see how they solved the problem, but I haven't found any (yet).
  Reply With Quote
02-17-14, 10:44 AM   #5
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
I haven't gone over the code, just replying to the last post:
When I wrote this add-on that moves things around inside the guild bank, I ran into the problem of item actions failing, which I solved by making a delay (arbitrarily set to 0.8 sec) between actions. From your description, I think this may solve your problem as well (although I'm baffled at the printed error message).
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
02-18-14, 06:14 PM   #6
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
Originally Posted by Malsomnus View Post
From your description, I think this may solve your problem as well (although I'm baffled at the printed error message).
Thanks! I looked at HappyHour and it planted a seed. After a few days of unsuccessful coroutine bashing, the light went off and I solved the problem by fetching items from the guild bank one at a time (one per click). While not ideal, it works. There's usually not that many items being fetched so I can live with it.

I posted an updated version here on WoWInterface.

Last edited by bsmorgan : 02-18-14 at 06:17 PM.
  Reply With Quote
03-07-14, 11:47 AM   #7
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
I was able to solve this problem the "correct" way using events. If you are curious see the code in Skillet - Beta.

During testing, I discovered that the code that fetched items from the player's bank could also get confused so I used the same method to solve that problem as well.

Last edited by bsmorgan : 03-07-14 at 11:49 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Fetching items from the GuildBank


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