Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: MuscleDGamer on Tue 27/08/2024 23:56:33

Title: Programming "Don't you think you should stand a little closer?" Hotspots?
Post by: MuscleDGamer on Tue 27/08/2024 23:56:33
So I'm just trying to get a hang of the ropes and such of AGS, figure out how to do certain things, how to program with it, etc etc; hopefully to try and make a Laura Bow style game--but I digress.

In quite a number of Sierra games, most of the time, they require you to stand NEXT to the object you're interacting with in order to take it or use it, etc. So I'm trying to set a provision that says basically...

"If [character] is standing next to object, then [text]. Otherwise, 'Don't you think you should stand a little closer?'" (hence the subject line)

What I have so far is a mess of me trying to figure out what anything really means, because I cannot wrap my brain around it. I set a hotspot around a door, and I want the game to check "is the character standing on top of that hotspot next to the door?" (If yes, then [text]--if not, then "don't you think..." yadda yadda).

function hDoor1_Tile_Stand()
{
  hDoor1.Enabled = true;
}

function hDoor1_Interact()
{
if (hDoor1.Enabled = false):
{
  Display("Don't you think you should stand a little closer?");
}
if (hDoor1.Enabled = true):
{
  Display("You open the door.");
}
}

I've been getting very overwhelmed looking through the index trying to figure out what would work. I honestly have no clue if I'm even thinking about it right at all or if my brain is just making stuff up with the limited knowledge I have.

Thank you  :)
Title: Re: Programming "Don't you think you should stand a little closer?" Hotspots?
Post by: Eon_Star on Wed 28/08/2024 12:00:52
Hi, you could try using a region close to your object. If the player is standing on the region, the function should work as scripted.

Happy scripting.
Title: Re: Programming "Don't you think you should stand a little closer?" Hotspots?
Post by: heltenjon on Wed 28/08/2024 12:02:29
You need to add some more things to this, like code for actually opening the door, but one error I can spot right away, is that you need to use double equals when checking a variable:

if (hDoor1.Enabled == false)
So: single equals sign when setting or changing the variable's value, double equals when comparing.

From the online scripting tutorial:

QuoteChecking variables

Obviously we need a way to find out what value our variable contains, otherwise it's useless. We do this using conditional statements, called if statements. An if statement looks like this:
  if (myCounter == 5)   
   {  
     myCounter = 0;
   }  

what this means is that if myCounter contains the value 5, then the script inside the { } brackets will be run (which in this case changes the value of myCounter to zero).
If myCounter does not equal 5, the script inside the brackets is not run and execution carries on from after the } .