[SOLVED] Inventory ItemAtIndex problem

Started by Cassiebsg, Mon 28/07/2014 16:48:12

Previous topic - Next topic

Cassiebsg

Hey again.

The past few days I've been working on my custom inventory again, this time trying to "polish" the edges that were/are missing.

As you may, or may not, remember I'm using 2 inventory windows. The players and the backpack. Now, there really is no meaning to have a backpack, if the player just can carry everything with him anyway, right? I have decided that I wanted the player to have 5 slots. One for the backpack, two pocket for small items, and two hands for medium/big objects. So far so good. I found the option ItemAtIndex, and _thought_ that was the solution, since then I could just reserve the slots/index to each hand/pocket... but (as you experienced guys already know) that doesn't really work. :(

So now, I have items that get added to the same slot/index, and adding an item to index 3, will result that I'm losing the item not from index 3, but from 0 (if that is the only item I have).

Is this possible to do? Should I create an array instead? Something else? I'm already using a few bool to determine if a hand/pocket is full or empty, but that does nothing but misfire, due to the index being "shuffled" by the number of items one actually has. :/

To resume, what I'm looking for is something like in Discworld, where you have the luggage for extra items, and a very limited of items that one actually can carry.

Again, I'm not looking for someone to code this for me, as I learn best at doing it on my own, and I get a much bigger satisfaction of coding knowing that "I did that!"
I just want a push/hint in the right direction, before I use a couple more days working with a code that won't work. ;)
There are those who believe that life here began out there...

Slasher

#1
Hi,

this is not to solve your inventory issue, though I'm sure you will get close to the mark solutions.

A player cannot have two different inventory's...  One way that I do it is to use a gui (could be your rucksack) with buttons (items) that act as a secondary inventory. You can add items to this new inventory or take them away. You can change the mouse cursor graphic like with the normal inventory. I have in fact used this method with a game I will be releasing later. It can be quite daunting but rewarding. Some may see this as an ideal way others may not.

This could be as simple or as complicated as you make it.

It's just food for thought.


Cassiebsg

#2
Thanks slasher, but that problem is solved for long. ;)

What I'm missing is limiting the players inventory items. I think I'm close to the solution, but am having trouble to get the right "if checks" to actually lose the correct inventory item....
Maybe it's just a matter of the code order, or maybe I'm missing something in my logic.

EDIT: After simplifying my code, I got the lose objects to work. Turns out it was just my logic, that made an error and I was unable to see it. Once I saw that the code was running in the simpler version, I managed to see my error. :) Now I just need to "polish this" and add a check to avoid a crash (if the players hands are full, he just adds the item to the backpack, but that crashes the game when I want to use an item from the backpack and the players hands are already full).

EDIT 2: Got this almost working now. But seems like every time I solve one "problem" I get a brand new one (or a repeat of one I had already solved)... but it's all a matter of logic and if/else checks that I'm having a problem with. so am sure I'll eventually get it.
Maybe I should just use a blank item to fill the index, and then just swap the items. At least that way I was sure what item was at what index and I could just use the lose/add at index like I wanted in the start...

This is ending to be more a "rambling" topic than technical... maybe it should be moved to the rumpus room? (If so, I'll make sure to edit the topic name to something more rumpus appropriate. LOL). ;)
There are those who believe that life here began out there...

Ghost

Quote from: slasher on Mon 28/07/2014 17:58:29
A player cannot have two different inventory's

Literally true, but each character you create can have his/her own inventory, and you can assign any character to an inventory window. A simple way would be to create "placeholder character" for the bags/packs etc, and set specific inv windows to these characters. While you will still have to check that the capacity is limited you can swap items around much more easily then.

The very useful Grid-Base Inventory module ( http://www.adventuregamestudio.co.uk/forums/index.php?topic=28177.msg636475095#msg636475095 ) is already custom-made to move items around between inventories- worth a look, maybe.

Cassiebsg

#4
Thanks Ghost.
The resources of this forum are endless. :) I'll try and figure out how that one works, but for now am almost content with my solution... almost, a few if/else still not working right (think it might me the || if option that I may be doing wrong).

EDIT: Alleluia! Alleluia! Alleluia! I finally "debugged" the last few errors in the code. :) So hopefully it'll work even when I have more items. Currently have few to test. Code is rather "ugly" and long though... almost sure you guys would code it in half or less of what I used... ROFL
If anyone is interested I'll post the code as is ATM.
Still rather disappointed about how ItemAtIndex works.
There are those who believe that life here began out there...

SMF spam blocked by CleanTalk