getinvname(i,buffer) no longer works

Started by spook1, Tue 13/06/2006 22:06:17

Previous topic - Next topic

spook1

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???

Code: ags

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++;
Ã,  }
}

strazer


Ashen

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

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.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk