Sunday, June 6, 2010

Selling/ Inventory Conundrum

Working on selling/ removing items from inventory. I have the basic selection part of the code done, but I still don't know how to go about re-ordering the inventory if an item is removed from the middle of the stack.

Here's the dilemma:
Say you have
4 Potions
2 Herbs
1 Sword
1 Shield

And you sell 2 Herbs. With the code I have so far, your inventory would then look like this:
4 Potions

1 Sword
1 Shield

So basically right now, I am brain storming different ways to recompile the list of inventory--hopefully without making the code too complex. I want it to end up as this:
4 Potions
1 Sword
1 Shield


Shouldn't be too hard, but will take a little thinking.

Also, I hope to work out an "organize" feature, that organizes Items you can use outside of battle, Weapons, Key items, and so on. I'm guessing that the key to my first problem will lead me to the solution of this one.

----
EDIT: Actually, while typing this I think I figured something out that will work! The code will basically check if a slot is empty, and then check if the next slot is empty. If the next slot isn't, it will take the values and print them onto the first slot, and then make the next slot empty. The only problem I can see from this is if there is two slots open--the initial check will see the that next slot is empty--BUT I think it will fix itself because the "next" slot will be checking for its next slot, so the item will move from that THEN the first check will move it up again.

YAY! Now, to test it out...

No comments:

Post a Comment