Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jojowl80 on Wed 17/06/2020 03:48:51

Title: Using Multiple items on a hotspot
Post by: Jojowl80 on Wed 17/06/2020 03:48:51
Hey so I have two Items I want the player to have before he can make coffee

Code (ags) Select


function hCoffeMaker_UseInv()
{
  if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
  player.Say("Giddyup!");
  sBrew.Play();
  Wait(150);
  player.Say("Oh boy, Coffee's ready!");
  sPour.Play();
  Wait(150);
  player.LoseInventory (iCcup);
  player.AddInventory(iCcupfull);



problem is if I use either item singularly it also makes the coffee. Want to make it so he has to have both items before he makes it
Title: Re: Using Multiple items on a hotspot
Post by: Gilbert on Wed 17/06/2020 06:14:12
That's because you did not enclose the codes after if(...) in braces {}, so that only the "Giddyup!" line was affected by the if condition, and the remaining lines would be executed regardless of the conditions.

So:
Code (ags) Select


function hCoffeMaker_UseInv()
{
  if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
  {
    player.Say("Giddyup!");
    sBrew.Play();
    Wait(150);
    player.Say("Oh boy, Coffee's ready!");
    sPour.Play();
    Wait(150);
    player.LoseInventory (iCcup);
    player.AddInventory(iCcupfull);
  }


Title: Re: Using Multiple items on a hotspot
Post by: Matti on Wed 17/06/2020 11:44:47
Also, right now the player could use any item to make the coffee. If you want them to only make coffee when using either the cup or the coffee on the coffeemaker, then add an extra condition:

Code (ags) Select

function hCoffeMaker_UseInv()
{
  if (player.ActiveInventory == iCoffee || player.ActiveInventory == ICcup)  // <---
  {
    if(player.HasInventory(iCoffee) && player.HasInventory(iCcup))
    {
      player.Say("Giddyup!");
      sBrew.Play();
      Wait(150);
      player.Say("Oh boy, Coffee's ready!");
      sPour.Play();
      Wait(150);
      player.LoseInventory (iCcup);
      player.AddInventory(iCcupfull);
    }
  }
}
Title: Re: Using Multiple items on a hotspot
Post by: Jojowl80 on Wed 17/06/2020 18:00:54
thanks!