Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Volcan on Sun 21/07/2013 18:39:34

Title: SOLVED: Nothing happens with region[1].RunInteraction(1)
Post by: Volcan on Sun 21/07/2013 18:39:34
There is two exits in bottom line and I want to go to different rooms when touching the bottom edge.

Code (AGS) Select
function room_LeaveBottom()
{
if (region[1].RunInteraction(1)){
  player.ChangeRoom(20, 231,  115);
}
}


Maybe this is the wrong way to code.
Title: Re: Nothing happens with region[1].RunInteraction(1)
Post by: geork on Sun 21/07/2013 21:10:56
It sounds like you want
Code (AGS) Select
Region.GetAtRoomXY(int x, int y) to check whether the character is standing on the region when he crosses the bottom edge. Your code would look something like:
Code (AGS) Select
function room_LeaveBottom()
{
if (Region.GetAtRoomXY(player.x, player.y) == region[1]){ //if the player is on region 1...
   player.ChangeRoom(20, 231,  115);
}
}


RunInteraction is used when you want to execute the same code that is executed when the player  stands on/walks on/walks off the region, so if you have the room function
Code (AGS) Select
function region1_WalksOnto()
{
  //Some Code
}

Then whenever you call
Code (AGS) Select
region[1].RunInteraction(1)
You're actually executing
Code (AGS) Select
//Some Code
...I think anyway - I haven't ever used RunInteraction (I usually just stick things in separate functions if they are going to be used multiple time) but that's the impression the manual gives...

Hope that helps!
Title: Re: Nothing happens with region[1].RunInteraction(1)
Post by: Volcan on Sun 21/07/2013 22:41:40
Thank you, geork.

The second code works.
Title: Re: SOLVED: Nothing happens with region[1].RunInteraction(1)
Post by: johanvepa on Sat 27/07/2013 10:16:28
You could simplify by not using the room_LeaveBottom function at all but simply put in two regions near the bottom of the screen and then execute player.ChangeRoom in both region_Walksonto functions.