A custom function not preforming its taks in the right order. [SOLVED]

Started by kinan___rod, Wed 08/07/2015 12:51:57

Previous topic - Next topic

kinan___rod

Couldn't fit a better description in the subject, I placed a number of function inside a function of my own because every time the player moves to a new room all those stuff should happen, so the main character should walk to an area (the door clicked by the player), change to the new room then walk a few steps from the door in the new room, what is happening though is that he is walking to the door then instead of waiting for the room to change he is preforming the other walking command before the room changes, this is the code:

Code: ags

function Chaning_Room(int x, int y, WalkWhere Walkwhere, int roomn, int rx, int ry, CharacterDirection direction, int wx, int wy){
  player.ChangeView(1); //Changed to walking view in case any other view was there
  StartCutscene(eSkipESCOnly); //start a cutscene in case the players wants to pass
  player.Walk(x, y, eBlock, Walkwhere); //walk to the door in the first room
  player.ChangeRoom(roomn, rx, ry, direction); //change to the new room
  player.Walk(wx, wy, eBlock, eAnywhere); //walk a few steps from the door once you arrive at the new room
  EndCutscene(); //end cutscene

  //the character is preforming both walking command before changing the room
}

Snarky

From the manual:

ChangeRoom
(Formerly known as NewRoom, which is now obsolete)
(Formerly known as NewRoomEx, which is now obsolete)
(Formerly known as NewRoomNPC, which is now obsolete)

Character.ChangeRoom(int room_number, optional int x, optional int y)

Changes the room that the character is in.

If you call this on the player character, then the game will move into the new room with them.

IMPORTANT: This command does not change the room immediately; instead, it will perform the actual room change once your script function has finished (This is to avoid problems with unloading the script while it is still running). This means that you should not use any other commands which rely on the new room (object positionings, and so on) after this command within the same function.

Crimson Wizard

#2
Yes, AGS has this limitation that it cannot change rooms in the middle of a script.

The solution for your case could be this: you store a special value in a global variable that would tell you this particular cutscene is going on, as well as coordinates, and in the other room's "After fade-in" event you check this variable and continue cutscene if required.

E.g.:
In the original script:
Code: ags

bool IsRoomChangingCutscene;
int NeedToWalkToX;
int NeedToWalkToY;

function Chaning_Room(int x, int y, WalkWhere Walkwhere, int roomn, int rx, int ry, CharacterDirection direction, int wx, int wy){
  player.ChangeView(1); //Changed to walking view in case any other view was there
  StartCutscene(eSkipESCOnly); //start a cutscene in case the players wants to pass
  IsRoomChangingCutscene = true; // <----------------
  NeedToWalkToX = wx; // <----------------
  NeedToWalkToY = wy; // <----------------
  player.Walk(x, y, eBlock, Walkwhere); //walk to the door in the first room
  player.ChangeRoom(roomn, rx, ry, direction); //change to the new room
}

function EndChangingRoom()
{
  if (IsRoomChangingCutscene){
    player.Walk(NeedToWalkToX, NeedToWalkToY, eBlock, eAnywhere); //walk a few steps from the door once you arrive at the new room
    EndCutscene(); //end cutscene
    IsRoomChangingCutscene = false;
  }
}


In the other room's script:
Code: ags

function room_AfterFadeIn()
{
  EndChangingRoom(); // call to finish the cutscene (in case it is playing)
}

kinan___rod

Oh thank you very much man! I went through the entire manual back when I started working but I forgot this detail, and I did not know it was related to char.changeroom itself, I thought I did something wrong with the script, anyway really thank you for this solution!

SMF spam blocked by CleanTalk