Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Sun 04/01/2009 22:27:29

Title: Listbox items to run script - SOLVED!
Post by: Gepard on Sun 04/01/2009 22:27:29
I dont know if Im doing something wrong, but I dont want to bother Ghost with it anymore  ;D so I post it here:

I want to have a listbox where I can add and remove items (well I already have this). If I click on some of the items, a script will run (for example a msg will display). I know how to do this (barely) and it works. For example if I click on one a message will display saying "one", and if i click on two a msg will display saying "two" of course, but when I remove item one, item two takes its place and when i click on item two, its says "one" :f ) So... What I need is some "manual for a simple" that will tell me step by step what to do. Pleeeeeeease! Pretty please.

Thank you!
Title: Re: Listbox items to run script
Post by: RickJ on Mon 05/01/2009 01:42:06
From what you describe it appears that you are displaying item's index number (i.e. it's location in the list) something like this:

     Display("You clicked on item number %d",MyList.SelectedIndex);


Perhaps what you want to do instead is to display the item's text like this

     Display("You clicked on item %s",MyList.Items[MyList.SelectedIndex]);

Title: Re: Listbox items to run script
Post by: Gepard on Mon 05/01/2009 12:18:45
Yes, but I dont want just a display message after I click on the item, that was just an example. I want a script to run (for example a player to go to a different room or so). Basically Im looking for the complete script for: function listboxname_SelectionChanged(GUIControl *control)
Title: Re: Listbox items to run script - still not solved
Post by: RickJ on Mon 05/01/2009 18:30:51
Ok, so if you have a listbox named MyList and put 2 items in it, "one" and "two" you could just so something like the following

     if (MyList.Items[MyList.SelectedIndex]=="two") {
          TwoFunction();
     }
     else if (MyList.Items[MyList.SelectedIndex]=="one") {
          OneFunction();
     }
Title: Re: Listbox items to run script - still not solved
Post by: Gepard on Mon 05/01/2009 20:03:09
Thank you thank you thank you! It works perfectly!