Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Fri 20/08/2010 03:27:21

Title: inventory item inside list box
Post by: Icey on Fri 20/08/2010 03:27:21
how do i something like this

if (listbox.hasitem("blank"){

}

cause I need an action to fire with a code to something like this and i cant use selected index cause the the item that is added might not get to be added to be called index 0 or 4 it might change if you put/register something before it.
Title: Re: how to do this!
Post by: Creator on Fri 20/08/2010 03:37:40
How about give the player an inventory item, or give another character an inventory item and checking if they have it?


if (player.HasInventory(iBlank))
{
    DoStuff();
}


To give characters inventory items:


player.AddInventory(iBlank);


Just replace player with another characters script name to use them as a "list".
Title: Re: how to do this!
Post by: Gilbert on Fri 20/08/2010 03:46:32
You may use a loop to check the entries of the listbox until a match is found.
For convenience, you may write a function like this (untested):

function FindInListbox(String text){
 int ii=0;
 int index=-1;
 while(ii<listbox.ItemCount){
   if (listbox.Items[ii]==text) {
     index=ii;
     ii=listbox.ItemCount;
  }
   ii++;
 }
 return index;
}

This function will return the entry with the first occurrence of the "text" parameter and return -1 if it is not found.

So, your code could be like:

if (FindInListbox("blank")>=0) {
}
Title: Re: how to do this!
Post by: GarageGothic on Fri 20/08/2010 03:48:09
bool hasitem(this ListBox*, String list_item) {
 int count;
 while (count < this.ItemCount) {
   if (this.Items[count] == list_item) return true;
   count++;
   }
 }


Not tested, but that's the basic principle at least.

Edit: Curse you Gilbet! ;) I might as well post this anyway.
Title: Re: how to do this!
Post by: Icey on Fri 20/08/2010 03:55:46
thanx you guys.one of these should work but i don't think i can use inventory as i left that alone and progressed into the list boxes 
Title: Re: how to do this!
Post by: Icey on Fri 20/08/2010 04:03:55
oh and btw the whole meaning of this that this box is used for cego active quest that he has to do and when you talk to the AI you will need "magic circles quest 1" to be in questbox(listbox name) then if it is the AI will say something but if you don't have this then she will say something opposite to the other response and nothing will happen important unless u do have the item.