Two conditions in variable

Started by sloppy, Sun 06/11/2005 17:38:50

Previous topic - Next topic

sloppy

What would be the best way to make it necessary that two conditions need to happen in a variable for a result?

For example, to get a key from a store owner, I have to give him flowers for his wife AND give him a certain document.  I want it that giving either one of these items by itself will result in a different response and being directed to a different dialog topic but not the key.

Nothing I try gives a good result.

Ashen

What have you tried? How are you giving the items, since you couldn't use two inventory items on him at the same time?

You could try using 2 variables - one for giving the flowers, one for the document - something like:
Code: ags

//Interact with store owner
if (giveflowers == 1 && givedocumnet == 1) { 
  // given both, get key
}
else if (givenflowers== 1) {
  //only given flowers, do one dialog
}
else if (givendocument == 1) {
  // only given document, do other dialog
}
else {
  // Given nothing, do something else
}


But, without knowing what you've already tried, it's hard to say.
I know what you're thinking ... Don't think that.

sloppy

Here's the problem.  I get the flowers and document from another room.  The result of that is "got_flowers=1" and "got_document=1", and both are in the inventory.
But it's GIVING both of these items to a character that should result in getting the key.  So I have the result as "give_item_flowers=1" and "give_item_document=1".

So here's what I tried in the "Use Inventory On Character" script:

if (got_flowers==1) {
   character[EGO].Say("Here's flowers, can I have the key?");
   character[LEO].Say("I also need document.");
    player.LoseInventory(inventory[3]);   
}
if (game.inv_activated==3) {
   give_item_flowers=1;
   }

if (got_document==1) {
   character[EGO].Say("Here's document, can I have key?");
   character[LEO].Say("I also need flowers.");
  player.LoseInventory(inventory[4]);

if (game.inv_activated==4) {
  give_item_document=1;
  }

if (give_item_document==1 && give_item_flowers==1) {
  character[LEO].Say("Okay, here's the key.");
    player.AddInventory(inventory[5]);
}

So now what happens is that whether I give the flowers or document, it goes through the first two results one after the other, and not the third.

How can this be done?  My brain is absolutely fried trying to figure this one out.

Wretched

#3
The third one wont run because game.inv_activated can only have one value, the third one should run the second time you give something.
However imo the whole thing is just wrong. I'd write it more explicitly, this is just psudo code, to show the logic.

if (player.ActiveInventory==iFlowers)
{
Ã,  player.LoseInventory(iFlowers);
Ã,  give_item_flowers=1;
Ã,  "Here's the flowers, can I have key?"
Ã,  if (give_item_document==0)
Ã,  {
Ã,  Ã,  Ã, "No I need doc."
Ã,  Ã,  Ã, // Automatically give document if player already has it
Ã,  Ã,  Ã, if (player.InventoryQuantity[iDoc.ID]>0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  "Here's the Doc."
Ã,  Ã,  Ã,  Ã, player.LoseInventory(iDoc);
       give_item_document=1;
Ã,  Ã,  Ã,  Ã, "Okay here's the key"
Ã,  Ã,  Ã,  Ã, player.AddInventory(iKey);
Ã,  Ã,  }
Ã,  }
Ã,  else
Ã,  {
Ã,  Ã,  Ã, "Okay here's the key"
Ã,  Ã,  Ã, player.AddInventory(iKey);
Ã,  }
}


then same again for giving the document, (swap all flowers to docs and vice versa).

sloppy

It's so close!
Everything works when you have only one of the objects in inventory.  You give it and the character asks for the other object before he gives the key.

The problem now is when both items are in the inventory.
You give one of the objects to the character, he'll ask for the other.  But then the player character immediately offers the other object and the receiving character says "Okay here's the key." and then gives it.

Any ideas?

Wretched

From your posts I was under the impression this is what you wanted to happen, just remove the automatically give part:

Remove this bit.

Ã,  Ã,  // Automatically give document if player already has it
Ã,  Ã,  Ã, if (player.InventoryQuantity[iDoc.ID]>0)
Ã,  Ã,  {
Ã,  Ã,  Ã,  "Here's the Doc."
Ã,  Ã,  Ã,  Ã, player.LoseInventory(iDoc);
Ã,  Ã,  Ã,  Ã, give_item_document=1;
Ã,  Ã,  Ã,  Ã, "Okay here's the key"
Ã,  Ã,  Ã,  Ã, player.AddInventory(iKey);
Ã,  Ã,  }

sloppy

I should have looked at it closer.  Now it works the way I want it to.
Thanks for your help!

SMF spam blocked by CleanTalk