ChangeRoom: room2 code running in room 1 [SOLVED]

Started by EnterTheStory (aka tolworthy), Sat 26/04/2008 13:44:28

Previous topic - Next topic

EnterTheStory (aka tolworthy)

Edit: after seven hours of trying I finaly found the solution. This code was being called twice. Nothing to see here.

[original post:]
I need to change rooms several times in the same cutscene. I understand that 'ChangeRoom' has to run as the last item in any script. So I wrote the following code (The actual function is very, very long, but I think these are the relevant parts:)

Code: ags

function runCutScene(String cutSceneName)
{	if(cutSceneName =="room1") {
	StartCutscene(eSkipAnyKeyOrMouseClick); 
	character[1].Say("I am now in room1");
	EndCutscene(); 
	player.ChangeRoom(2) return; }
	if(cutSceneName =="room2") {
	StartCutscene(eSkipAnyKeyOrMouseClick); 
	character[2].Say("I am now in room2");
	EndCutscene(); 
	player.ChangeRoom(3) return;}
}

A user clicks in room 1 to call runCutScene(1).
runCutScene(2) is called automatically when room 2 loads, after fade in.
Result: CRASH: AGS complains about two instances of 'ChangeRoom' being queued.
So I tried again:

Code: ags

function runCutScene(String cutSceneName)
{	if(cutSceneName =="inside") {
 StartCutscene(eSkipAnyKeyOrMouseClick); 
	character[1].Say("I am now inside");
	EndCutscene();
	setTimerToWaitThenChangeScene(2); return; }
	if(cutSceneName =="outside") {
	StartCutscene(eSkipAnyKeyOrMouseClick); 
	character[2].Say("I am now outside");
	EndCutscene(); 
	setTimerToWaitThenChangeScene(3);
	return; }
}

This is the same, except runCutScene(1) ends by setting a global timer. This is checked by repeatedlyExecute. When the timer ends, the player moves to the new room. This time the room loads properly, but "I am now in room2" is spoken in room 1, BEFORE the room changes!

Any idea what's happening, and how I can fix it?

(edited to clarify what room is what)

SMF spam blocked by CleanTalk