Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: spook1 on Tue 13/06/2006 22:06:17

Title: getinvname(i,buffer) no longer works
Post by: spook1 on Tue 13/06/2006 22:06:17
I have a scriptline:

GetInvName(i,buffer) in a loop.
It is obsolete but by what code can I replace it?
InventoryItem.name cannot work, but what then???


function geefterug(String inv_item){
Ã, 
Ã,  int i ;
Ã,  String buffer;
Ã, 
Ã,  i=1;
Ã,  buffer = "NONE";
Ã, 
Ã,  while (i<14){Ã,  // do loop until inv item is returned or all inv_item slots (until 13) are checked

Ã,  Ã,  Ã,  Ã, 
GetInvName(i,buffer);Ã,  Ã,  Ã,  Ã,  Ã,  // check if it has the correct name
Ã,  Ã,  Ã,  Ã,  Ã, if (StrComp(inv_item,buffer)==0) {Ã,  Ã,  Ã,  Ã,  //if so:
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  if (character[EGO].inv[i] == 0){Ã,  Ã, //and if EGO does not already carry this inv_item
AddInventory(i); //add inv item

return i; //output inv_numer returned
i=14;Ã,  Ã,  Ã,  Ã,  Ã,  //stops while loop
Ã,  Ã,  }
}
Ã,  i++;
Ã,  }
}
Title: Re: getinvname(i,buffer) no longer works
Post by: strazer on Tue 13/06/2006 22:14:33
It's inventory.Name
Title: Re: getinvname(i,buffer) no longer works
Post by: Ashen on Tue 13/06/2006 22:39:52
What version are you using? You've mixed up the new String type and usage (buffer = "NONE";) and the old string stuff (StrComp(inv_item, buffer)).

For V2.71 it would be something like:

function geefterug(String inv_item){

  int i = 1 ;

  while (i<14){  // do loop until inv item is returned or all inv_item slots (until 13) are checked
    if (inventory[i].Name == inv_item && cEgo.InventoryQuantity[i] == 0){
      cEgo.AddInventory(inventory[i]);
      return i; // 'return' should end the while loop, no need for 'i = 14'
    }
    i ++
  }
  return 0; // No matching item name found
}


For V2.7, you'll need to use inventory.GetName(buffer) (which should be linked in the manual, if you look up GetInvName()) and the Character.InventoryQuantity property instead of character.inv, but it's otherwise pretty much as you've got it.