Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: R4L on Thu 24/08/2006 11:40:49

Title: Inventory help (SOLVED)
Post by: R4L on Thu 24/08/2006 11:40:49
Now I have another problem, concerning inventory. On GUI STATUSLINE I also have inventory. There are five boxes, and I would like only one item to be displayed in each. I made 5 different inventory windows, but whenever I pick up something in the game, the same items go into the first box. This is the first time I have tried to actually create inventory as I usually use the default GUI to do that.
Title: Re: Inventory Help
Post by: Joe on Thu 24/08/2006 12:58:42
Do you mean some thing like this?

(http://www.subir-imagenes.com/subir-fotos-imagenes/930c2b9d9c.jpg) (http://www.subir-imagenes.com)

Maybe you forgot setting the item height and width.
Title: Re: Inventory Help
Post by: monkey0506 on Thu 24/08/2006 13:08:24
That shouldn't do that unless the item height and width were set to 0...o.0 I think.

Anyway, they don't default to 0.

What he probably did is he probably drew different InventoryWindows for each item.

You just draw one window that contains all the item's spaces. Then you set the Item height and width.
Title: Re: Inventory Help
Post by: R4L on Thu 24/08/2006 13:12:50
I did this (http://www.2dadventure.com/ags/guiexplain.PNG).

I already set the item width and height. I just need to be able to show one inventory item in each black box, and each box can only show one item. My problem is that I don't know how to limit the amount of inv items per box, and let the player pick up items in any order.
Title: Re: Inventory Help
Post by: SSH on Thu 24/08/2006 13:23:26
So you want the first box always contains the Spanner, for example, if you have it. The next box only contains the Briefcase, etc.

Right, so there's a number of ways of doing this:

1. Use GUI buttons instead and change the graphic in on_event when event is addinventory

2. Use 5 dummy characters, each of whom can only pick up one particular item, and set each gui inv window to point to one of them

3. Set the width of inv items to be the distance between top right corners of your "holes", make the inv window go over all of them, and then

4. Always have all items in your inventory, but make them default to invisible sprites and turn the sprites to normal when you get the item...

5. Look at the entires to the Grid-based inventory coding competition

and many more...
Title: Re: Inventory Help
Post by: R4L on Thu 24/08/2006 14:15:58
What I meant SSH is that I have alot of inventory items, and I want the player to be able to pick them up in any order. For example, the player has nothing, and then he picks up a wrench. The wrench will be in box one. But if he has another item in the first box, the wrench will be put in box two. I understand if this is too complicated. I would rather not try to code all of this, especially since I may not understand any of it. So what I think I might do is instead of show individual boxes, im going to have a whole slot, which will have one InventoryWindow and show up to 5 items. This can be accomplished with ItemsPerRow correct?
Title: Re: Inventory help
Post by: monkey0506 on Thu 24/08/2006 23:33:32
You draw ONE InventoryWindow. Then you can add them and they should show up in the appropriate location (based on the ItemHeight and ItemWidth). You can't manually set ItemsPerRow. That's determined by the ItemWidth and Width (of the InvWindow).

[EDIT:]

I guess I didn't completely read it correctly. Ashen got it.
Title: Re: Inventory help
Post by: Ashen on Thu 24/08/2006 23:41:44
If I'm understanding you right, you don't care WHAT order the items are in, provided the most recently added item is the first in the InvWindow, rather than the last?

From the manual (Characeter.AddInventory):
Quote
By default, the new item is added to the end of the character's inventory list. However, you can insert it in a particular position in the list by supplying the second parameter. The new item is inserted before the current item at addAtIndex. Indexes are numbered from 0, so to add the item at the start of the list, pass 0 as the second parameter.

So, just adding 0 to all your AddInventory commands should do it.

EDIT: Re-reading it, I might've got what you want totally backwards. Just using a single InvWidow, and possibly using the ItemWidth property to set spacing, might be enough for what you want.
Title: Re: Inventory help
Post by: R4L on Fri 25/08/2006 00:21:30
Okay I got it now. My icons were 16 by 16, and I set the inv window to hold 8 items. Thanks for the help everyone!