Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Mon 02/04/2012 16:48:47

Title: Listbox: Have no Items Selected
Post by: steptoe on Mon 02/04/2012 16:48:47
Hi

I'm checking through the manual/forums to see if I can use a ListBox string name rather than ID.

It seems first item added is 0 then 1 then 2 etc etc

Obviously I need to check which item has been selected before running events for that item.

At the moment an event will run if ID 0 is selected from Listbox irrespective of what it is..


ListBox1.AddItem("Key");



EDIT


Global takes this but goes to else (having clicked 'Key' in the ListBox)


function ListBox1_OnSelectionChanged(GUIControl *control)
{
 if(ListBox1.ID==Key)
 { Display("Perhaps you should find out who has had the key lately");
 } else
 { Display("Sorry no go!");
 }
 }




I need to check that "Key" has been selected from ListBox before events are run.

Could someone give me a hand please?

Title: Re: Listbox String select help needed
Post by: Khris on Mon 02/04/2012 17:21:26
Listbox.ID is the number of the listbox in the GUI's .Controls array. For instance, if you added the listbox to a blank GUI, the ID is 0.

You're looking for .SelectedIndex.

  String itemname = ListBox1.Items[ListBox1.SelectedIndex];

  if (itemname == "Key") {
    ...
  }
Title: Re: Listbox String select help needed
Post by: steptoe on Mon 02/04/2012 17:26:22
Thank you so much Khris...

Great help to me

steptoe


Title: Re: SOLVED: Listbox String select help needed
Post by: steptoe on Tue 03/04/2012 14:04:17
EDIT....
Added a dummy blank item and now seems to work as expected...



-------------------------------------------------------

I am trying to NOT have any of the Listbox Items actually selected until you have actually selected any of them.  Khris, the code you gave me works up to that point.

What  I am working on is that after selecting an item in the ListBox is to have the mouse change graphic and use that on characters to revoke that particular subject conversation. Almost Active Inventory like.

In the manual it states: -1 to remove the highlight but obviously I may/may not need some kind of blind item?

Meanwhile I will keep reading the manual plus any help here will hopefully guide me through this.

cheers