Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 12/08/2004 05:14:51

Title: help! - moving npcs to different rooms
Post by: on Thu 12/08/2004 05:14:51
hey, i'm pretty new to AGS and i'm currently working on my first game.  after completing a cutscene i want to move two NPCs instantly to a different room, however i can't find a function that would do that for me. i could create new characters with the same animations and have them start in the new room, but then i'd have the old characters still stuck in the first one. make sense?

sorry if this is a ridiculous question, if this has been covered elsewhere a link would also be helpful. thanks!
Title: Re: help! - moving npcs to different rooms
Post by: Alynn on Thu 12/08/2004 06:02:05
character[ID].room = roomNumber;

There you go... just make sure the character in question is not moving before you do it... You can even do a custom function

NPCNewRoomEx(int id, int room, int x, int y) {
     StopMoving(id);
     character[id].x = x;
     character[id].y = y;
     character[id].room = room;
}

You can do the same thing for NPCNewRoom just omit the things for the x and y positions of the character...
Title: Re: help! - moving npcs to different rooms
Post by: on Thu 12/08/2004 08:27:00
already here's what i got so far. the top 3 lines are the ending lines of my cutscene. i did a copy and paste of your script and then filled in the room number and x/y coordinates i need for my characters, but i got either an 'unexpected' or an 'undefined token' error message for the lines around the first NPCNewRoomEx function. the undefined token thing i solved by adding the function part in front of it, and i got rid of the unexpected error by adding the closing bracket after the cutscene, but not I get an error message that says "Error (line 21): PE03: Parse error at '0.'"  Line 21 is the line that the first NPCNewRoomEx function is on. 


FadeOut(1);
EndCutscene();
NewRoomEx(3,110,127);
}
function NPCNewRoomEx (RYANSIT,3,235,124) {
     StopMoving(RYANSIT);
     character[RYANSIT].x =235;
     character[RYANSIT].y = 124;
     character[RYANSIT].room = 3;
}
function NPCNewRoomEx (BRINSIT,3,197,123) {
     StopMoving(BRINSIT);
     character[BRINSIT].x = 197;
     character[BRINSIT].y = 123;
     character[BRINSIT].room = 3;
}
Title: Re: help! - moving npcs to different rooms
Post by: Gilbert on Thu 12/08/2004 08:56:37
It's not used that way, you have to define the function somewhere early in the whole script (i.e. not inside some interactions, etc.), and then call it whenever you need to use them.

I'll suggest you put the function declaration on top of the global script, import it in the script header so they'll be accessible via room scripts. Details follows:

1. Declare the function on top of your global script:
Ã,  Ã,  - Open and edit the global script (shortcut in editor: Ctrl-G).
Ã,  Ã,  - Put the following lines on top of it:

Ã,  Ã, functionÃ,  NPCNewRoomEx(int id, int room, int x, int y) {
Ã,  Ã,  Ã,  Ã,  StopMoving(id);
Ã,  Ã,  Ã,  Ã,  character[id].x = x;
Ã,  Ã,  Ã,  Ã,  character[id].y = y;
Ã,  Ã,  Ã,  Ã,  character[id].room = room;
Ã,  Ã, }


2. import the function in the script header:
Ã,  Ã, - Open and edit the script header (shortcut in editor: Ctrl-H).
Ã,   - Put the following line in it:

Ã,  Ã, importÃ,  functionÃ,  NPCNewRoomEx(int id, int room, int x, int y);

Now, you can just call the function with parameters needed anywhere in your script.
For example if you want to Put character PAUL to (120,45) of room 4 after the end of a cutscene:

StartCutscene(1);
//blah bla bla...
EndCutscene();
NPCNewRoomEx(PAUL, 4, 120, 45);
Title: Re: help! - moving npcs to different rooms
Post by: on Thu 12/08/2004 09:17:11
thanks, that helps a lot. while you were replying i stumbled across something that described basically that, except a lot more long-windedly (?). i tried everything out and now everythings gravy. thanks a ton!
Title: Re: help! - moving npcs to different rooms
Post by: SilverWizard_OTF on Thu 12/08/2004 09:17:39
At the intercation editor, (after your cutscene) cal RunScript, and type:
     FadeOut();
Then close the script, and choose MoveNpcToDifferentRoom .
Then call again RunScript, and type:
      FadeIn();

I hoped i helped you a bit.

Or you can, after your cutscene, immediately choose MoveNpcToDifferentRoom, from the interaction editor.