Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Torchiest on Fri 27/10/2023 15:05:50

Title: Getting dialog to appear before Display function runs
Post by: Torchiest on Fri 27/10/2023 15:05:50
I've got the following script that runs when trying to interact with a door:

function hDoor_Interact()
{
  if (KeyInDoor)
  {
    cEgo.Walk(960, 620, eBlock);
    dGetKey.Start();
    KeyInDoor = false;
    GiveScore(5);
    Display("You grab the keys, happy to have them.");
  }
  else
  {
    Display("You don't need anything from there right now.");
  }
}

And then the dialog is simply this:

// Dialog script file
@S  // Dialog startup entry point
EGO: My keys were in the door!
stop

The Display function always runs before the dialog. I've tried calling Wait() with some number in it between the Start() and Display() calls, but it just delays both the text popup and the dialog, still showing the window first. I'd assume this is a common coding situation, but I've having a really hard time getting useful search results. Hopefully I'm just unaware of some simple way to make this work. Can anyone help?
Title: Re: Getting dialog to appear before Display function runs
Post by: Torchiest on Fri 27/10/2023 15:26:03
After more digging, I figured out how to do this, so I'm posting my solution here for posterity:

I needed to add a special function call in the dialog as follows:

// Dialog script file
@S  // Dialog startup entry point
EGO: My keys were in the door!
run-script 1
stop

That calls the special function with the integer usable to decide what to do. So I changed that function to include the Display() call:

function dialog_request(int param)
{
  switch(param) {
    case 1:
    {
      Display("You grab the keys, happy to have them.");
      break;
    }
  }
}

I am curious why this has to be done this way instead of it just synchronously flowing through the original code, if any can explain that.
Title: Re: Getting dialog to appear before Display function runs
Post by: Crimson Wizard on Fri 27/10/2023 15:36:12
Hello.
In this case you do not have to use run-script, but put these commands directly in the dialog script, indenting by at least 1 space:

Code (ags) Select
// Dialog script file
@S  // Dialog startup entry point
EGO: My keys were in the door!
  Display("You grab the keys, happy to have them.");
stop

This is explained in the manual:
https://adventuregamestudio.github.io/ags-manual/DialogScript.html#using-regular-scripting-commands-in-dialogs


In regards to order of actions, Dialog.Start does not start dialog immediately, but schedules it until the current script event ends ("hDoor_Interact" in your case). Dialog is run afterwards.
Title: Re: Getting dialog to appear before Display function runs
Post by: Torchiest on Fri 27/10/2023 15:43:58
Ah, thank you. For some reason the tutorial gave me the impression the dialog scripting was much more limited than the regular scripting and couldn't do things like that.
Title: Re: Getting dialog to appear before Display function runs
Post by: Torchiest on Fri 27/10/2023 15:48:13
Just to follow up, this is what I was referring to in the tutorial. https://adventuregamestudio.github.io/ags-manual/acintro8.html

"This is not the same type of script that we've used for our Events like picking up the key. It's a much simpler dialog-only scripting language."
Title: Re: Getting dialog to appear before Display function runs
Post by: Crimson Wizard on Fri 27/10/2023 16:20:06
Quote from: Torchiest on Fri 27/10/2023 15:48:13Just to follow up, this is what I was referring to in the tutorial. https://adventuregamestudio.github.io/ags-manual/acintro8.html

"This is not the same type of script that we've used for our Events like picking up the key. It's a much simpler dialog-only scripting language."

Unfortunately some parts of the manual are outdated... it's not being updated as often as it should.
I will mark that this needs an update, perhaps pointing out that you may add regular script commands in a dialog too.
Title: Re: Getting dialog to appear before Display function runs
Post by: Matti on Fri 27/10/2023 17:27:53
I'm a bit confused about why you need that dialog at all. Can't you just put
cEgo.Say("My keys were in the door!");in the hDoor_Interact script?
Title: Re: Getting dialog to appear before Display function runs
Post by: Torchiest on Fri 27/10/2023 17:58:48
Quote from: Matti on Fri 27/10/2023 17:27:53I'm a bit confused about why you need that dialog at all. Can't you just put
cEgo.Say("My keys were in the door!");in the hDoor_Interact script?

Yes, yes I can. I didn't know that function existed lol. I assumed the dialog functionality was the only way to get characters to speak. I'll have to check out the character functions more deeply from now on.
Title: Re: Getting dialog to appear before Display function runs
Post by: Matti on Fri 27/10/2023 18:03:00
I would recommend going through the whole list once:

https://adventuregamestudio.github.io/ags-manual/Character.html