How to remove item from container in party backback?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Mebaru
Posts: 19
Joined: Sun Oct 14, 2012 2:03 pm

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

Post 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".
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

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

Post by Montis »

I think you have to use the function

Code: Select all

Champion:removeItem(slot)
for items in the inventory.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
Mebaru
Posts: 19
Joined: Sun Oct 14, 2012 2:03 pm

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

Post by Mebaru »

Champion:removeItem() will remove container, not item in this container.
Mebaru
Posts: 19
Joined: Sun Oct 14, 2012 2:03 pm

How to remove item from container in party backback?

Post 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.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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
Finished Dungeons - complete mods to play
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

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

Post 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().
Mebaru
Posts: 19
Joined: Sun Oct 14, 2012 2:03 pm

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

Post 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.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

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

Post by petri »

Thanks for the feedback! I've added Item:removeItem() to my todo list.
Mebaru
Posts: 19
Joined: Sun Oct 14, 2012 2:03 pm

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

Post by Mebaru »

petri wrote:Thanks for the feedback! I've added Item:removeItem() to my todo list.
Great news, thanks!
Post Reply