inventory item inside list box

Started by Icey, Fri 20/08/2010 03:27:21

Previous topic - Next topic

Icey

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.

Creator

How about give the player an inventory item, or give another character an inventory item and checking if they have it?

Code: ags

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


To give characters inventory items:

Code: ags

player.AddInventory(iBlank);


Just replace player with another characters script name to use them as a "list".

Gilbert

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):
Code: ags

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:
Code: ags

if (FindInListbox("blank")>=0) {
}

GarageGothic

Code: ags
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.

Icey

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

Icey

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.

SMF spam blocked by CleanTalk