Best way to compare / access inventory item as object?

Started by fratello Manu, Mon 15/02/2021 11:46:33

Previous topic - Next topic

fratello Manu

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
// 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
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!

Crimson Wizard

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

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?

SMF spam blocked by CleanTalk