I am having trouble storing the location of my character when entering a room(2)/minigame, so that the character on exit of the room/mini game returns to where they were.
This if what I tried:
function room_Load()
{
if (player.PreviousRoom != 2) //to store your location before you entered this room
{
LeaveGunfight = player.PreviousRoom;
LeaveX = player.x;
LeaveY = player.y;
}
function room_AfterFadeIn()
{
cJose.x = 320;
cJose.y = 300;
}
and linked to a button on a GUI that pops up asking if you would like to retry:
function BtnNoRetry_OnClick(GUIControl *control, MouseButton button)
{
gRetry.Visible = false;
player.ChangeRoom(LeaveGunfight, LeaveX, LeaveY);
}
The player always returns to 320, 300
I don't get it, is it due to the order things are called??
EDIT: um, I apologize, the previous answer was wrong.
I just made a test with similar code and it worked for me.
You could try putting "Display("%d , %d", LeaveX, LeaveY);" in "AfterFadeIn" and before changing rooms to see if they store proper values.
I assume you're calling player.ChangeRoom(2); to switch to the mini game, right?
Try replacing that with
LeaveX = player.x; // this should be the only place that sets LeaveX,Y
LeaveY = player.y;
player.ChangeRoom(2);
Upon exiting, call player.ChangeRoom(player.PreviousRoom, LeaveX, LeaveY);
I also assume that LeaveX,Y are global variables (and not declared in a script's header)?
Thanks guys,
Used your tips an found the bug was my fault.. (put coordinates in the PlayerChangeRoom(2, 320,300)) I don't know why I didn't catch that :-[
Code in first post works fine, declared LeaveGunFight, LeaveX and LeaveY as global int's
Thanks again!