Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Fri 16/08/2019 10:29:39

Title: Why aren't these added inventory items showing up?
Post by: bx83 on Fri 16/08/2019 10:29:39
I've added this piece of code - it's supposed to transfer inventory items from cDummy to player (cJulius):


  //lose playerstartswith items from inventory - now it's totally empty
  cJulius.LoseInventory(iKnife);
  cJulius.LoseInventory(iRope);
  cJulius.LoseInventory(iNotepad);
 
  cDummy.AddInventory(iCarCoolant); //4
  cDummy.AddInventory(iCarPetrol);  //5
  cDummy.AddInventory(iFacePlate);  //6
  cDummy.AddInventory(iFuzzyDice);  //8

  cJulius.AddInventory(iFurstPrize);    //68

  //get all other inventory items
  for (int i = 1; i <= 10; i++) {
    player.InventoryQuantity[i] = cDummy.InventoryQuantity[i];

    //the below 2 lines report that items 4, 5, 6, and 8 are '1' for both
    Display("dummy %d inventory %d",i, cDummy.InventoryQuantity[i]);
    Display("julius %d inventory %d",i, player.InventoryQuantity[i]);

    //set dummy inventory quantity to 0 - delete this item from the inventory
    cDummy.InventoryQuantity[i] = 0;
  }


Then I have a look at the inventory - only iFurstPrize (68) is in there, not items 4, 5, 6, and 8.
Same thing happens if I put 'cJulius' instead of 'player'.

What's going on?

This is a modified version of the code used in the game, given to me by CrimsonWizard a while ago, to transfer items between 2 inventories.
Title: Re: Why aren't these added inventory items showing up?
Post by: Matti on Fri 16/08/2019 10:42:17
The help file entry on InventoryQuantity says: "If you change this array directly, the on-screen inventory will not be updated. In this case, you must call UpdateInventory to see any new or removed items."

That might be the problem.
Title: Re: Why aren't these added inventory items showing up?
Post by: bx83 on Fri 16/08/2019 12:10:56
Works :)
Thanks :)
Title: Re: Why aren't these added inventory items showing up?
Post by: Matti on Sat 17/08/2019 13:30:18
I'm glad to be of help  :)

Btw, it would be convenient if you put a [SOLVED] in your thread's titles so that people know that there's no need for help anymore.