Hello!
Situation:
- the player (cEgo) is in room 53
- The NPC is in room 52
- When the time runs out and if the player is not in room 52, another character, cNPC, will take over in room 52
Here's the code in Global script:
if (IsTimerExpired (19))
{
if (cEgo.Room != 52)
{
cNPC.SetAsPlayer();
cNPC.Walk (1239, 458, eBlock, eWalkableAreas); // <<<< [b]ERROR HERE[/b]
cNPC.FaceDirection (eDirectionRight);
cNPC.Say ("Oh well...");
aElevatorOpen.Play();
// STUFF happening
}
}
The error I get is: "Character is not in current room".
I managed to change rooms with SetAsPlayer before, but in this case it's the Timer that triggers the switch and there's a cutscene following automatically.
Any ideas?
Thx!
EDIT : When I remove everything cutscene after cNPC.SetAsPlayer(); the switch works
What happens if you swap cNPC with Player in the rest of the commands after SetAsPlayer?
A room change command (such as ChangeRoom) is not executed right away, but is scheduled and executed when the current script ends. If SetAsPlayer triggers a room change, then the room change is also scheduled and executed after your script.
You need to stop your script right after cNPC.SetAsPlayer(); and perform the rest of commands in that room's "After fade in" event.
Quote from: heltenjon on Wed 28/05/2025 21:51:35What happens if you swap cNPC with Player in the rest of the commands after SetAsPlayer?
Nothing will be different, as using "player" and a player character's name produce equivalent results.
Oh nice! OK, didn't know about that. And my script got a lot shorter. Thank you so much for your help! (nod)