Get inv. item number from list box and showing it's image

Started by Saberteeth, Thu 25/05/2006 16:43:46

Previous topic - Next topic

Saberteeth

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--

deftonesrule

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.

Ashen

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:

Code: ags

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.
I know what you're thinking ... Don't think that.

Saberteeth

So, where do I set this code, in the interface_click?

Ashen

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.
I know what you're thinking ... Don't think that.

Saberteeth

I use 2.71 but still script in 2.62  :-[ Anyway, I'll use the code and get back to you if it works.

deftonesrule

oh.. so you want it to display like...
_______________________
[itemname1  ............ image]
-------------------------------------
[itemname2  ............ image]
-------------------------------------
[itemname3  ............ image]
-------------------------------------

? sounds pretty tight.. !

Ashen

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.
I know what you're thinking ... Don't think that.

Saberteeth

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--

SMF spam blocked by CleanTalk