Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: paolo on Mon 27/10/2008 10:15:03

Title: Dialog and Changeroom problems (SOLVED)
Post by: paolo on Mon 27/10/2008 10:15:03
Sigh, never try to debug other people's code (although that's a large part of what I do for a living, but that's another story...).

The code I'm having problems with has a dialog that contains a "new-room" function. In the room_AfterFadeIn() function for the room that the character goes to there are five calls to dialog[xx].Start(), each followed by the animation of two NPCs:


function room_AfterFadeIn()
{
  dialog[26].Start();
  character[35].LockView(76);
  character[35].Animate(0, 5, eOnce, eBlock);
  character[35].UnlockView();
  character[34].LockView(77);
  character[34].Animate(0, 3, eOnce, eBlock);
  character[34].UnlockView();
  dialog[27].Start();
  // snip
  character[35].Say("says something here");
  character[0].ChangeRoom(12,170,180);    // this is the PC
  character[34].ChangeRoom(-1,100,100);
  Wait(100);
  character[0].Say("something else here");
}


The final part of the code is intended to move both NPCs out of the room and to move the PC back to the room he was in when the original dialog started.

To sum up, we have a call from a dialog to change room, run several dialogs and then change back to the room we started from.

What happens is that the game changes to the new room and the animation runs several times, but the dialogs do not start up. Then the command to move the PC back to the original room causes the following crash: "Error: NewRoom: Cannot queue action, post-script queue full".

What should happen, fairly obviously, is that the the first dialog playes, then when the appropriate topic is chosen, the game changes to the new room, we see the dialogs, the animations run in between them and then the player gets moved back to the original room.

It looks like this code has got itself a bit tied up in knots and a script is not returning in time for something else to happen, or something like that.

Can anyone suggest how to fix this? I'm using v3.0.0.23. Thanks very much.
Title: Re: Dialog and Changeroom problems
Post by: TwinMoon on Mon 27/10/2008 11:09:01
I think you forgot that dialogs don't start until the current block of code has finished.

You can probably fix this by putting the code into a dialog_request.
(You then use a run-script at the end of both dialogs 26 and 27.)


if (value==26) { //called from dialog 26
  character[35].LockView(76);
  character[35].Animate(0, 5, eOnce, eBlock);
  character[35].UnlockView();
  character[34].LockView(77);
  character[34].Animate(0, 3, eOnce, eBlock);
  character[34].UnlockView();
}
if (value==27) { //called from dialog 27
  // snip
  character[35].Say("says something here");
  character[0].ChangeRoom(12,170,180);    // this is the PC
  character[34].ChangeRoom(-1,100,100);
  Wait(100);
  character[0].Say("something else here");
}
Title: Re: Dialog and Changeroom problems
Post by: Khris on Mon 27/10/2008 11:09:36
Dialogs aren't run until the end of the function, just like the player's room changes, meaning every Dialog.Start(); and player.ChangeRoom(...) get queued. This screws up the order and causes the error.

In the past, it was possible to run code after a dialog by using a second RunScript-action; unfortunately there's still no proper way to do this in 3.x.
(I once mentioned adding being able to link several functions to an event, but I don't know what happened to that request.)

Running code after a room change is not necessary; put it in after fade-in of the subsequent room.

So in short: merge dialogs 26 & 27, do the animations in between using run-script X / dialog_request, and move everything supposed to happen after the room change to the next room.
Title: Re: Dialog and Changeroom problems
Post by: paolo on Mon 27/10/2008 11:26:28
Quote from: TwinMoon on Mon 27/10/2008 11:09:01
I think you forgot that dialogs don't start until the current block of code has finished.

I thought it would be something like that.

Quote from: KhrisMUC on Mon 27/10/2008 11:09:36
In the past, it was possible to run code after a dialog by using a second RunScript-action; unfortunately there's still no proper way to do this in 3.x.

Ah, now that makes sense. I didn't mention that this is code is ported from 2.7x, which would explain why it probably worked before.

Thanks for the responses. I'll check out what works and give an update for other people's reference.

EDIT: Yep, that works fine now. I just had to make sure that the calls to start the dialogs were at the end of each function. So I now have:


function room_AfterFadeIn()
{
  //some initial stuff here
  dialog[26].Start();
}


and each dialog has a run-script in it. Then dialog_request() runs the animations, plays the sounds and then starts the next dialog.

Thanks for your help, guys.