Why aren't these added inventory items showing up?

Started by bx83, Fri 16/08/2019 10:29:39

Previous topic - Next topic

bx83

I've added this piece of code - it's supposed to transfer inventory items from cDummy to player (cJulius):

Code: ags

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

Matti

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.

bx83


Matti

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.

SMF spam blocked by CleanTalk