Adding any word someone types into the parser into inventory.

Started by eminigalaxy, Thu 20/06/2024 17:55:24

Previous topic - Next topic

eminigalaxy

I need help trying to figure out how to code a part in my game where the player can type the name of any ingredient into the parser and it will be added to the inventory (the inventory is just a simple list of words). I've tried two different ways but have gotten two errors (cannot convert 'Const string' to 'inventory item*' & cannot convert 'bool' to 'string*') with it and can't figure out any other ways. Or if it can even be done.
I never rlly know what I'm doing but that's life. || WIP: Dilvemma

Crimson Wizard

#1
Please post your scripts that did not work, it may be easier to tell how to fix the script.

Also, you say that "the inventory is just a simple list of words", but then mention that something cannot be converted to  'inventory item*'. Are you trying to also use Inventory Items somewhere in this?

Khris

You cannot use built-in inventory items for this. You need an array of strings instead:

Code: ags
String inv_item[100]; // array
int inv_count;  // count size

// add new string to array
function AddItem(String name) {
  if (inv_count == 100) { Display("Inv item limit reached!"); return; }
  inv_item[inv_count] = name;
  inv_count++;
}

Snarky

You say "add any word someone types," but do you mean any word, or just any word that is actually the name of an inventory item in the game?

If what you want is the first option, that's what Khris's code will let you do. If it's the second, you can do:

Code: ags
function AddItem(String name)
{
  for(int i=0; i<Game.InventoryItemCount;i++)
  {
    if(inventory[i].Name == name)
    {
      player.AddInventory(inventory[i]);
      break;
    }
  }
}

SMF spam blocked by CleanTalk