Can i reuse an item over and over?

Started by Axelord1942, Tue 15/01/2019 12:22:53

Previous topic - Next topic

Axelord1942

I know this is probably simple, but hear me out.

Player can craft different items. If the player gets some iwirebits from one location, crafts an item, and then finds some more iwirebits later and crafts a different item with it later, will this cause a conflict?

I ask because I'm getting a strange bug where I'm getting a duplicate of a component after using it in a new recipe.

I looked through ~390 different forum posts with the various search terms with "item issues, item duplicating, etc. etc."

Code is as follows:

Code: ags

function ismallbat_UseInv()
{
  if (player.ActiveInventory == iwirebits)
    {
      Display ("You wrap the wire around the battery.");
      player.LoseInventory(iwirebits);
      player.LoseInventory(ismallbat);
      player.AddInventory(iwirebat);
    }
  else (player.ActiveInventory !=iwirebits)
    {
      Display ("That doesn't seem to work.");
    }
}


Am I using this wrong?  Any help would be appreciated, I'm trying to fix this so I can put my demo up.
You have been eaten by a Gru

Khris

Code looks fine, can you expand on the bug? What do you mean by "duplicate component"?

Inventory is essentially an array (Character.InventoryQuantity). If your game has five items, and the player picked up the first two once and the third item twice, their inventory array is:  [1, 1, 2, 0, 0]
Each time you call Add/LoseInventory, the number is incremented / decremented. That's all there is to it.

Axelord1942

So the item iwirebits is used in two different recipes.

When I use the item for the first recipe, it disappears like normal.

When I use it on the second recipe, (after picking the iwirebitis item up again and NOT having one already in inventory) I get the correct item in response but I also received a duplicate of the iwirebits item. (as if .LoseInventory wasn't used)

It happened twice, but just now I tried to duplicate it and it didn't happen.

I'm going to keep trying to duplicate it again.

Could it just be a random bug?  I'll keep the debug console open next time it happens and see if there's any more info I can provide.
You have been eaten by a Gru

Axelord1942

Send the grue in after me.

I was overlooking a loose bit of code from a now removed event where the player was awarded the item in question, consider this closed.

><*
You have been eaten by a Gru

SMF spam blocked by CleanTalk