Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akumayo on Sun 11/09/2005 17:22:23

Title: Stacking Inventory
Post by: Akumayo on Sun 11/09/2005 17:22:23
I know there is an option on the main game screen editor for "Display multiple items multiple times."  I normally tick this, but my inventories always flood.  I don't really value the idea of a scrolling inventory, so my question is this:
How do you stack inventory items, displaying how many you have on each icon, without creating inventory items that actually have the number as part of their sprite?

I considered using globalints to track how much you have, but the problem remains, how do you display to the player how much they have?
Title: Re: Stacking Inventory
Post by: Ishmael on Sun 11/09/2005 17:49:02
Mark up a co-ordinate spot of every item slot, and place a labe somewhere on each slot, where you want the number to be displayed, and in the repeadetly_execute check which item is at which co-ordinates, and change the label by each slot to the number of items on each slot. I think you can get the number of items with cCHARID.inv[item] (was character[CHARID].inv[] in the old scripting), once you know which number to supply as item.
Title: Re: Stacking Inventory
Post by: Akumayo on Sun 11/09/2005 17:51:21
hrm....I'm still not good at setting label text, how would you do it?
Title: Re: Stacking Inventory
Post by: Ishmael on Sun 11/09/2005 17:54:56
Label.SetText. Look it up in the manual for exact instructions on how to use it ;)
Title: Re: Stacking Inventory
Post by: Akumayo on Sun 11/09/2005 18:02:18
Okay, nevermind, I found a SetLabelText script in one of my old games, it should work, another question though, how exactly do I determine which inv slot to put the labels on, I mean, what if Label 1 is set to Slot 1, meat, and the player gets a rib first instead of meat?
Title: Re: Stacking Inventory
Post by: Ishmael on Sun 11/09/2005 19:59:36
The InventoryItem.GetAtScreenXY(mouse.x, mouse.y); will tell you what item is where, just mark down one point from each slot, and go through every slot to get, for example, an array of inv item numbers, which you can then use as reference in, for example, a while loop that sets the labels based on the inv item numbers.
Title: Re: Stacking Inventory
Post by: Akumayo on Sun 11/09/2005 20:02:05
Hrm...that sounds rather difficult, I'll just break down and use scrolling buttons, thanks for your help though!
Title: Re: Stacking Inventory
Post by: Ishmael on Sun 11/09/2005 20:27:28
You give up too easily :P

Here're some bits of code I thought up:

start of global script:
int itemcount[8];

repeadetly_execute (or someplace else, like where the inventory is brought up, if it's not visible all the time):
InventoryItem *itemcount[1] = InventoryItem.GetAtScreenXY(20, 20);
InventoryItem *itemcount[2] = InventoryItem.GetAtScreenXY(40, 20);
InventoryItem *itemcount[3] = InventoryItem.GetAtScreenXY(60, 20);
InventoryItem *itemcount[4] = InventoryItem.GetAtScreenXY(80, 20);
InventoryItem *itemcount[5] = InventoryItem.GetAtScreenXY(20, 40);
InventoryItem *itemcount[6] = InventoryItem.GetAtScreenXY(40, 40);
InventoryItem *itemcount[7] = InventoryItem.GetAtScreenXY(60, 40);
InventoryItem *itemcount[8] = InventoryItem.GetAtScreenXY(80, 40);
Inv1.SetText("%d", itemcount[1]);
Inv2.SetText("%d", itemcount[2]);
Inv3.SetText("%d", itemcount[3]);
Inv4.SetText("%d", itemcount[4]);
Inv5.SetText("%d", itemcount[5]);
Inv6.SetText("%d", itemcount[6]);
Inv7.SetText("%d", itemcount[7]);
Inv8.SetText("%d", itemcount[8]);

Very simple stuff, and I don't guarantee it works, as I haven't tested it, and I'm not yet that familiar with the new scripting, but anyway...