Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Saberteeth on Thu 25/05/2006 16:43:46

Title: Get inv. item number from list box and showing it's image
Post by: Saberteeth on Thu 25/05/2006 16:43:46
Ok, just as the topic implies: I'm aving problems with the list box. I want the player to be able to see all of his inventory items in a list box. And then, when the item is highlighted, to show it's image on the GUI. How can I do this? I know, a totally noobish question but I want to release my first game, I really do. :) I hope I'm not violating any rules and if this question has been asked before, please direct me to it.

--SaberT--
Title: Re: Get inv. item number from list box and showing it's image
Post by: deftonesrule on Thu 25/05/2006 19:44:16
i recently learned how to make a inventory menu.

as far as i know the list box is only for saves. youll want to click the red thumbs up button for add gui inventory window. I replaced the original one so its using the same names for buttons and all. it was pretty easy and a noob like me didnt need any help for it.

when you click on inventoy in your hud, the inv window will pop-up, then you can set it so you can use look controls to identify what each item is.

of course import your inv images as sprites and then into your inventory menu in ags, and during the game, use an interaction on whatever so its like game-give player an inventory item(#)

replace # with the number of the inventory item you want.

anything more advanced then that is beyond my reach.
Title: Re: Get inv. item number from list box and showing it's image
Post by: Ashen on Thu 25/05/2006 21:19:34
I've done someting like this a while back in V2.62, let me see if I can update it...
You'll need to include an Inventory Window control on your GUI, and make it just big enough for one item. Then you'll need to add some code to fill out the list box everytime the inventory GUI is opened, something like:


lstMyList.Clear();
int Temp;
while (Temp < invMyInv.ItemCount) {
  lstMyList.AddItem(invMyInv.ItemAtIndex[Temp].Name);
  Temp ++;
}

(Where lstMyList and invMyInv are the script names of your ListBox and InvWindow.)
Then set the ListBox's code to change the InvWindow's top item (the only one you'll see, remember), to the selected index (invMyInv.TopItem = lstMyList.SelectedIndex;).
This is rough and from memory so it mightn't work quite as-is, but it should point you in the right direction at least.
Title: Re: Get inv. item number from list box and showing it's image
Post by: Saberteeth on Fri 26/05/2006 08:22:27
So, where do I set this code, in the interface_click?
Title: Re: Get inv. item number from list box and showing it's image
Post by: Ashen on Fri 26/05/2006 10:45:21
What AGS version are you using? If it's 2.7 or higher, you shouldn't be using interface_click. If it's 2.62 then yes it goes in interface_click, but that code won't work as it's the 2.71 version.

The sample code needs to go wherever you turn the Inventory GUI on - so the Control Functions for any Buttons that turn it on, on_key_press, etc. You might want to add it to the existing show_inventory_window function, set that to turn your GUI on, and call it rather than pasting the code in multiple times. If your Inv GUI is always on display, you'll need to add that code to update the ListBox everytime a new item is added - again, a custom function might be easier.

The invMyInv.TopItem = lstMyList.SelectedIndex; bit needs to go in the Control Function for the ListBox.
Title: Re: Get inv. item number from list box and showing it's image
Post by: Saberteeth on Fri 26/05/2006 10:47:39
I use 2.71 but still script in 2.62  :-[ Anyway, I'll use the code and get back to you if it works.
Title: Re: Get inv. item number from list box and showing it's image
Post by: deftonesrule on Fri 26/05/2006 12:56:39
oh.. so you want it to display like...
_______________________
[itemname1  ............ image]
-------------------------------------
[itemname2  ............ image]
-------------------------------------
[itemname3  ............ image]
-------------------------------------

? sounds pretty tight.. !
Title: Re: Get inv. item number from list box and showing it's image
Post by: Ashen on Fri 26/05/2006 14:33:02
I saw it more as:

_______________________
[itemname1]             [ image]
-------------------------------------
[itemname2]   
-------------------------------------
[itemname3]                 [USE]
-------------------------------------
[itemname4]                   [OK]
-------------------------------------

But the other way would work to, you just need to alter the height of the InvWindow, and code the Scroll buttons so the InvWindow and ListBox are always in sync.
Title: Re: Get inv. item number from list box and showing it's image
Post by: Saberteeth on Fri 26/05/2006 20:28:48
Ok, this is getting me nowhere. I've tried to impliment your code, Ashen, and failed miserably. So I tried to script myself,...and failed even more. Don't get me wrong, I'm no noob at scripting, but 2.62 scripting is nowhere near the 2.71 scripting. Maybe to most of you it looks easy and simple but I don't think so. So I abandoned the idea of the list box and went for the simple yet effective SCUMM interface which is easier to script(I wanted to script the whole thing myself and not use the template) and guess what, it works now(not the list box thing, SCUMM).

Thank you Ashen and deftonesrule for trying to help me(you probably did but I don't know that :)).

--SaberT--