[Solved] Storing Room Coordinates for ChangeRoom()

Started by MiteWiseacreLives!, Wed 10/06/2015 07:07:43

Previous topic - Next topic

MiteWiseacreLives!

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:
Code: ags


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:
Code: ags

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??

Crimson Wizard

#1
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.

Khris

I assume you're calling player.ChangeRoom(2); to switch to the mini game, right?
Try replacing that with
Code: ags
  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)?

MiteWiseacreLives!

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!

SMF spam blocked by CleanTalk