Problem with moving NPC after activating dialog option

Started by HolyJack, Tue 21/08/2007 11:45:28

Previous topic - Next topic

HolyJack

Hi!

I'm just starting out with AGS and I have a problem with my test game.

I have a NPC standing in a room, and I what I want to do is to start up a dialog with him and
when I select a certain dialog option (enabled only when EGO has a certain item in his inventory), I want the NPC to speak a line, move and then exit the room.

However I'm having problems. When I try to do this, no matter how I try to do it, the NPC ends up exiting the room before the dialog has finished.

What should I do?

Candall

What you're probably going to need to do is use a dialog_request script and call it from the dialogue script.  Here's an example.

Code: ags

//This goes in the Global Script
function dialog_request (int scriptnumber) {
  if (scriptnumber==1){
    cNPC.Walk(x, y, eBlock);
    cNPC.ChangeRoom(x);  //or however you handle room transitions
  }
}


This has set up your dialog_request function and introduced a variable.  You can only use ONE parameter from the run-script call (which we'll get to in a minute), so I usually use that parameter to call blocks of code as needed.

Now here's how you're going to call that script:

Code: ags

//This goes in the SCRIPT FOR THE DIALOGUE!
@X  //option x
NPC: You have the inventory item in question.
NPC: I will now walk away.
run-script 1 
stop


run-script is used inside a dialogue script.  Notice the number "1."  This tells the function dialog_request to set the value of its variable "scriptnumber" to be "1."

Khris

Just to be thorough:
Quote from: manualNOTE: The conversation will not start immediately; instead, it will be run when the current script function finishes executing.

If you want code to be run immediately after a dialog, add a second RunScript action after the one calling dDialog.Start(), then put it in there.

Candall

Quote from: KhrisMUC on Tue 21/08/2007 18:05:25
add a second RunScript action after the one calling dDialog.Start(), then put it in there.

Wait, is this assuming that there's an entirely new dialogue being called to start from within one that's already going?  I thought he needed the script run from a dialogue option, not an entirely new dialogue... or did I miss something?

Khris

I also thought dialog_request is the obvious solution at first, but then I read this:
Quote from: HolyJack on Tue 21/08/2007 11:45:28When I try to do this, no matter how I try to do it, the NPC ends up exiting the room before the dialog has finished.
That's why I explained how to run code after a dialog.

Edit: "it" refers to "code", not to a second dialog.

SMF spam blocked by CleanTalk