Add inventory problem

Started by Gepard, Fri 25/02/2011 17:30:57

Previous topic - Next topic

Gepard

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:

Code: ags
 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:

Code: ags

    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!
Drink up me 'arties! Yo ho!

Gilbert

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.

selmiak

maybe some more brackets will help:

Code: ags

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.

SMF spam blocked by CleanTalk