Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Theyeyboss on Fri 24/02/2017 18:25:20

Title: Unlock interaction.
Post by: Theyeyboss on Fri 24/02/2017 18:25:20
Hello. I need help to solve my problem. I've tried looking for a solution to this problem but I have found none. Basically, the player needs to go to bed, but before he can do that, he needs to talk to another character, but only after talking to that character. It's hard to explain, but basically, if the player doesn't talk to the other character, when he clicks the bed, he says he needs to talk to the other character first. After talking to the other character, when the player clicks the bed the room changes. How do I do that?
Title: Re: Unlock interaction.
Post by: Cassiebsg on Fri 24/02/2017 18:54:29
Create a global bool variable called talkedToCharacter, set it to false. Once you talk to the character, add talkedToCharacter=true;

Then find your your bed code, and add
Code (ags) Select

if (talkedToCharacter) // if he has talked to the character
{
    // sleep code
}
else  // else he has not talked to the character
{
    // he says he needs to talk to the other character first code
}
Title: Re: Unlock interaction.
Post by: Theyeyboss on Fri 24/02/2017 19:23:08
But what do I do if the bed is a hotspot? (Sorry for being a noob, but I forgot to include that detail in the original post).
Title: Re: Unlock interaction.
Post by: Slasher on Fri 24/02/2017 19:29:05
Quote from: Theyeyboss on Fri 24/02/2017 19:23:08
But what do I do if the bed is a hotspot? (Sorry for being a noob, but I forgot to include that detail in the original post).

Just add it to the bed Hotspot properties.

When you try to get in it..

Code (ags) Select

function hHotspot3_Interact() // Bed hotspot's name
{
if (talkedToCharacter) // if he has talked to the character
{
    // sleep code
}
else  // else he has not talked to the character
{
    // he says he needs to talk to the other character first code
}
}


Title: Re: Unlock interaction.
Post by: Khris on Mon 27/02/2017 12:42:26
Theyeyboss, nothing in the explanation you got changes depending on what kind of game object the bed is.

The extremely common and basic beginner's problem you have is solved by using a variable. This variable is tested in whatever the interaction happens to be you want to have different outcomes depending on the variable's value.

Cassiebsg's code goes into the event's function, whether the bed is a hotspot or not, just like with any other interaction.

I'll repeat the code, this time with proper indentation:
function hBed_Interact()
{
  if (talkedToCharacter)
  {
    // sleep commands
  }
  else
  {
    Display("I have to talk to X first.");
  }
}


(I would also ask all tech support posters TO DO THE SAME.)