Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: BigHairyEyeball on Wed 02/08/2017 21:43:57

Title: Need help triggering a function when the player moves past a y coordinate SOLVED
Post by: BigHairyEyeball on Wed 02/08/2017 21:43:57
Basically, I'm setting up a "trap" the player has to solve - the player needs to retrieve an item to progress in the game, but walking forward triggers a trap that kills him. I've got everything else worked out, but I can't seem to find the bit of code that tracks when the character walks past a certain point on the board. i.e., if the character walks past 122 on the y coordinate, an event starts. Is there a line of code that controls this?

Thanks in advance!
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: horusr on Wed 02/08/2017 22:12:51
You can use room edges for that. Or put a hotspot and when player walks on it it triggers function. Or you can use repeadetly_execute and check player.Y and if it is bigger than that then trigger function
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: Cassiebsg on Wed 02/08/2017 23:15:14
Or create a Region for the event. I would probably just check the players y coord, and then act accordingly. All depends what is easier for you.
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: BigHairyEyeball on Thu 03/08/2017 05:04:36
How do you check the player's Y coordinate? Is there a specific line of code for it? I literally am teaching myself as I go, so some of the particulars are beyond me.

In addition, this may sound like a weird question, but has anyone had any problems with the LeaveRoom functions in rooms after using a hotspot to transition from one room to another? I've got this one area where you click on the middle of the screen to advance to the next room, but after that room, the LeaveRoom code isn't working for some reason.

Sorry to be such a pain about this. I literally spent the whole evening banging my head against the code and nothing seemed to work.
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: Kara Jo Kalinowski on Thu 03/08/2017 06:51:13
charactername.y to get the y value. It's a property of that character
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: horusr on Thu 03/08/2017 06:58:10
What Morgan saya.
Code (ags) Select
if (player.Y > 122)
{//code you have}


Don't forget to put it in repeadetly_execute ()
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: BigHairyEyeball on Thu 03/08/2017 11:49:53
Thanks! I'll give it a shot!
Title: Re: Need help triggering a function when the player moves past a y coordinate
Post by: BigHairyEyeball on Thu 03/08/2017 12:11:46
... got it to work. Also, figured out that I've been forgetting to use the event handler on my screen whenever I create a changeroom function. Holy shnike.

Don't code tired, kids.