Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Sat 11/12/2010 06:46:25

Title: Problem with 2 conditions for if function
Post by: barefoot on Sat 11/12/2010 06:46:25
Hi

I think my mind's gone dead because I can't quite get this to script to work.

I want to check for two conditions if an active inventory item is clicked on another inventory item:

if (player.ActiveInventory == idriver) AND if {player.HasInventory(iwire));  An action happens and of course an ELSE Display("You need some wire first");

In the inventory you can have an electrical plug, screwdriver, pliers and

wire. You should only be able to use the screwdriver on the plug if you have the wire...

Something like this:


function iplug_UseInv()
{
  if (player.ActiveInventory == iscrew)
  if (player.HasInventory(iwire))

   
   Display("You use the screwdriver to attach the wire to the plug");
   cChris.LoseInventory(iwire);
   cChris.LoseInventory(iplug);
   cChris.LoseInventory(iscrew);
   cChris.AddInventory(iplugwire);
   Display("You now have a plug with some electrical wire attached.");
}


Should i try and use a dummy screwdriver until the wire has been got or is there a better way?

Can someone with a sound mind please advice..?

cheers

barefoot

Title: Re: Problem with 2 conditions for if function
Post by: ThreeOhFour on Sat 11/12/2010 07:02:00
Sounds like you want something like:


function iplug_UseInv()
{
  if (player.ActiveInventory == iscrew && player.HasInventory(iwire))
  {
    Display("You use the screwdriver to attach the wire to the plug");
    cChris.LoseInventory(iwire);
    cChris.LoseInventory(iplug);
    cChris.LoseInventory(iscrew);
    cChris.AddInventory(iplugwire);
    Display("You now have a plug with some electrical wire attached.");
  }
}
Title: Re: Problem with 2 conditions for if function
Post by: barefoot on Sat 11/12/2010 11:37:07
Sounds good Ben.. of course i should have known.. or do but not on all cylinders at the moment...

cheers
barefoot