Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gepard on Fri 25/02/2011 17:30:57

Title: Add inventory problem
Post by: Gepard on Fri 25/02/2011 17:30:57
I am working on a game in AGS 2.7something. With the help of many of you I managed to create a system like this.

Player comes to a NPC and in dialog he chooses Trade option. Dialog request script runs like this:

if (parameter==59) {
  if (character[MR].InventoryQuantity[ibandage.ID] < 2) character[MR].AddInventory (ibandage);
  gTrade.Visible = true;
  chmoney = Merchant;
  sellerlabel.Text = "Merchant";
  int i = 1;
  while (i <= Game.InventoryItemCount) {
   character[INV3].InventoryQuantity[i] += character[MR].InventoryQuantity[i];
   character[MR].InventoryQuantity[i] = 0;
   i++;
  }
  UpdateInventory ();
}


In global script (game start) I have this:


   sellstuff.CharacterToUse = cF;
   giveinv.CharacterToUse = cInv1;
   takeinv.CharacterToUse = cInv2;
   sellerinv.CharacterToUse = cInv3;
//Traders
//Merchant (Vaspun)
Merchant = 1000;
character[MR].AddInventory (ibandage);


The problem is that even if that character has more than 2 bandages, he still gets new bandage every time I want to trade with him (every time the dialog request script runs). Any idea why? Thanks!
Title: Re: Add inventory problem
Post by: Gilbert on Sat 26/02/2011 14:48:02
Quote from: Gepard on Fri 25/02/2011 17:30:57
The problem is that even if that character has more than 2 bandages, he still gets new bandage every time I want to trade with him (every time the dialog request script runs).
I don't know what "that character" you are referring to here, do you mean MR or INV3?
I actually don't quite understand your codes, but from my understanding, due to the while loop, MR will lose ALL his items after the trading. This will cause the < 2 condition to be true after the "trading"(?) and so the "trading" can still be continued to carry out. The number of this item INV3 is carrying will also just increase without bound, every time this part of the codes is executed.
Title: Re: Add inventory problem
Post by: selmiak on Sat 26/02/2011 15:12:06
maybe some more brackets will help:


if (parameter==59) {
   if (character[MR].InventoryQuantity[ibandage.ID] < 2) {
   character[MR].AddInventory (ibandage);
   gTrade.Visible = true;
   chmoney = Merchant;
   sellerlabel.Text = "Merchant";
   int i = 1;
   while (i <= Game.InventoryItemCount) {
    character[INV3].InventoryQuantity[i] += character[MR].InventoryQuantity[i];
    character[MR].InventoryQuantity[i] = 0;
    i++;
   }
   UpdateInventory ();
}
}


I tend to use brackets even if the if clause is just one line. Makes it easier to understand the code and add stuff into the bracket.