Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Mon 15/02/2021 11:46:33

Title: Best way to compare / access inventory item as object?
Post by: fratello Manu on Mon 15/02/2021 11:46:33
Hi everyone!

I'm trying to cycle all inventory items to set their "description" (so actually its "Name", in code)
I think I'm doing something wrong comparing the objects:

Code (ags) Select
// for every inv: assigning name
function CompileInvNames()
{
  int ic = 0;
 
  while(ic<Game.InventoryItemCount)
  {
      ic++;
      inventory[ic].Name = GetInvName(inventory[ic]);
   }
}


and the called function is:

Code (ags) Select
String GetInvName(InventoryItem* inv)
{

  switch(inv)
  {
    case iMyInventory1:
      return "This is the name for iMyInventory1";
   
    case iMyInventory2:
      return "This is the name for iMyInventory2";
     
    // etc......
  }
}


...where iMyInventory1 is the object itself, so the "name" in AGS editor.

What I'm doing wrong?

Thanks!
Title: Re: Best way to compare / access inventory item as object?
Post by: Crimson Wizard on Mon 15/02/2021 11:50:43
Please tell, what exactly is wrong? Do you get errors, or result is not correct?

Also, maybe I am missing something, but why do you need this GetInvName function and this switch, when you can do this:

Code (ags) Select

iMyInventory1.Name = "This is the name for iMyInventory1";
iMyInventory2.Name = "This is the name for iMyInventory2";
...


And even then, you can also just set the Description in the editor. Maybe you change this description later at some point? Or something is not working as you want?