Can NPCs change rooms without instantaneously disappearing?

Started by jfarwyke, Tue 21/04/2009 19:08:52

Previous topic - Next topic

jfarwyke

The manual tells me that when a NPC changes rooms, he does so instantly. I've found this is true. Even when I code him to walk off the edge of the screen and then change rooms, in runtime he doesn't even walk, he just vanishes. I've tried using regions as well. My question is, is there any way at all to have him walk off screen and then change rooms? And even more so, I'm curious, can he be performing functions in the other room without the playable character even there to see it? I'm not married to the idea, so don't go to any trouble experimenting, if you don't already know a solution. I just made a part of my game where my playable character (who's a sort of dog) can bark at these animals which scares them off in different directions. And I was playing with the idea that perhaps he can (if he chooses) to follow one into the next room to see it continuing it's journey. If the solution is far too complex, I'll probably dump the idea, as it's uneccessary to the game and kind of frivolous. Later on, I'll have much more important problems that I'll need your help with - all you smart folks out there, you know who you are. Thanks.   

monkey0506

You could put into the room's repeatedly execute function the script to do:

Code: ags
int i = 0;
while (i < Game.CharacterCount) {
  if (Region.GetAtRoomXY(character[i].x, character[i].y) == LEFT) character[i].ChangeRoom(LEFT);
  if (Region.GetAtRoomXY(character[i].x, character[i].y) == RIGHT) character[i].ChangeRoom(RIGHT);
  if (Region.GetAtRoomXY(character[i].x, character[i].y) == TOP) character[i].ChangeRoom(TOP);
  if (Region.GetAtRoomXY(character[i].x, character[i].y) == BOTTOM) character[i].ChangeRoom(BOTTOM);
}


Replacing the LEFT, RIGHT, TOP, BOTTOM with the appropriate values for each region/room. Then just don't call ChangeRoom at all and let the room's repeatedly execute handle it.

And AFAIK NPCs can perform actions in other rooms, but I believe that any blocking actions would still be done in a non-blocking and possibly even instantaneous fashion.

Khris

To make a character walk off the screen, then disappear, use something like:

Code: ags
  cGuy.Walk(340, cGuy.y, eBlock, eAnywhere);
  cGuy.ChangeRoom(3);


Use eBlock to make them walk to the destination before changing the room, eAnywhere to allow them to leave the walkable areas (which naturally can't continue outside the background).

monkey0506

That works if he wants the walk to be blocking but if he wants the character to walk off screen non-blocking it doesn't work at all.

NiksterG

Another solution is to have the character walk away with the normal Walk command, then in the repeatedly_execute function check to see if the character is moving. If not, change the room, if yes, don't.

I'm thinking something like this:

In function where character changes rooms:
Code: ags

cCharToChangeRooms.Walk(X, Y);


In the repeatedly_execute function:
Code: ags

if (cCharToChangeRooms.Moving == false)
    cCharToChangeRooms.ChangeRoom();


That will enable the player to continue moving or doing whatever while the other character moves off screen and then changes rooms.
Check out my games! (Not all made with AGS)

SMF spam blocked by CleanTalk