Page 1 of 1

item:destroy() fails on item from container in backpack

Posted: Tue Oct 23, 2012 11:58 pm
by Mebaru
Hello,
stuck with weird problem. Party has a container in backpack and I want to destroy item in that container via item:destroy. The issue is item is not destroyed and on next iteration it crashes with "bad object" error.

Quick example:

Code: Select all

for ii in ito:containedItems() do											
	for j = 1, #fd do				
		if ii.name == fd[j] then
			print("Found. Destroying "..ii.name)
			ii:destroy()
			break
		end																		
	end										
end
On first pass it founds item and fires ii:destroy() but item is still seen in container. On next iteration it crashes with "bad object".

Re: item:destroy() fails on item from container in backpack

Posted: Wed Oct 24, 2012 11:36 am
by Montis
I think you have to use the function

Code: Select all

Champion:removeItem(slot)
for items in the inventory.

Re: item:destroy() fails on item from container in backpack

Posted: Wed Oct 24, 2012 5:46 pm
by Mebaru
Champion:removeItem() will remove container, not item in this container.

How to remove item from container in party backback?

Posted: Thu Oct 25, 2012 6:45 pm
by Mebaru
Ok, as I wan't lucky to get any useful feedback on my previous topic on same subject, I try once more.

I need to remove a specific item from party equipment slots/backpack. Item should be removed, if it is in container too as well.
On my tests, items in containers are not removed properly. You can remove item in regular slot with Champion:removeItem() or direct item:destroy - both work ok. But if I use item:destroy() on item in container, it fails silently - item stays in container. And next time you trying to access this item - game crashes with "bad object" error.

Will really appreciate any help on this.

Re: How to remove item from container in party backback?

Posted: Thu Oct 25, 2012 6:55 pm
by Komag
best to keep it to one thread. a new post in the thread bumps it to the top so we can all see again just fine.

I think this may be a difficult problem, I certainly don't know what approach to use, hopefully someone can tackle it

Re: How to remove item from container in party backback?

Posted: Fri Oct 26, 2012 1:29 am
by Grimwold
I've done a little testing on this and I'm not sure you are going to be able to do what you want... containers don't seem to behave consistently... for example you can iterate the contents of a container like so:

Code: Select all

for item in sack_1:containedItems() do
and you can add items with:

Code: Select all

sack_1:addItem(spawn("pitroot_bread"))
but you can't remove items... as removeItem(1) fails (unless container slots are numbered differently)

Also.. you can only do the above if the container is on the ground... if it is in a champions backpack you can't even do sack_1:containedItems().

Re: How to remove item from container in party backback?

Posted: Fri Oct 26, 2012 1:53 am
by Mebaru
Iterating items for container in party backpack works ok. I can iterate through all items, I can add items to container. But I can't destroy items from it, alas. This seem to be a bug imho.

Re: How to remove item from container in party backback?

Posted: Fri Oct 26, 2012 7:37 pm
by petri
Thanks for the feedback! I've added Item:removeItem() to my todo list.

Re: How to remove item from container in party backback?

Posted: Fri Oct 26, 2012 9:16 pm
by Mebaru
petri wrote:Thanks for the feedback! I've added Item:removeItem() to my todo list.
Great news, thanks!