Page 1 of 1

(fixed) Some help with wiping out and replacing inventory...

Posted: Thu Dec 06, 2007 12:04 am
by Remy
I needed a way to wipe out a champion's inventory, and replace it, and I have a method, but I'm not really happy with it.
This is how I'm doing it - first, I iterate through all the inventory slots, and delete any instances found:

Code: Select all

--clear inventory 
        for i_slot = 0, 29, 1 do 
                local id = dsb_fetch(PARTY, 0, i_slot, 0) 
                if (id) then destroy_instance(id) end 
        end 
I had to use a special function for deletion, because if one of the items was a container, simply deleting it caused a segmentation error (I assume because there were a set of insts floating in nowhere). The function looks like this:

Code: Select all

function destroy_instance(id) 
        inv, count = dsb_fetch(IN_OBJ, id, -1, 0) 
        if(count) and (count > 0) then 
                for k, v in pairs(inv) do 
                        destroy_instance(v) 
                end 
        end 
        dsb_delete(id) 
end 
It's recursive so that it will dig through containers inside containers (technically, I didn't need it in this case, but I figured it might be useful).
The next part is the part that's giving me problems.
I do a set of dsb_spawns, but it seems to not quite process in order. The newly spawned items get destroyed along with everything else (except when the slot I'm spawning to was empty to start with - in other words, if I spawn to right hand, and the right hand was empty to start with, it works. If there was something there, both are deleted). I'm not quite sure why, but it may be because the function wrapping this inventory reset is immediately followed by a dsb_fullscreen call.
But, if I put the spawns in a delayed function, it works - that's the part I dislike. Once the fullscreen returns, there's a fraction of a second before the inventory blinks into existance. It's not horrible, I'm just wondering if there's a better way.

Posted: Thu Dec 06, 2007 2:34 am
by Sophia
Remy wrote:I had to use a special function for deletion, because if one of the items was a container, simply deleting it caused a segmentation error (I assume because there were a set of insts floating in nowhere).
DSB is supposed to push all of the instances in a container to LIMBO if you delete the container. Unfortunately, in some cases, it tries to free() a pointer that it had already freed previously, and occasionally that causes everything to come tumbling down. I'm actually glad it segfaulted so abruptly for you-- those bugs are hard to track down! I've fixed this.

Anyway, since you want to destroy the instances, not just limbo them, you'll still need your function. :)
Remy wrote:The next part is the part that's giving me problems.
I do a set of dsb_spawns, but it seems to not quite process in order.
This is a bug, too.
DSB queues some changes to the dungeon and only executes them when the current event is finished processing, in order to prevent a huge mess, when, say, you delete the trigger you're standing on. In this case, the deletes got put into the queue, but the spawns didn't. So, when it tried to spawn into a full location, the old inst was still there (causing the spawn to fail), and then got deleted. I've corrected this, too.

In short, none of this was your fault. ;)