Getting dialog to appear before Display function runs

Started by Torchiest, Fri 27/10/2023 15:05:50

Previous topic - Next topic

Torchiest

I've got the following script that runs when trying to interact with a door:

Code: ags
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:

Code: ags
// 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?

Torchiest

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:

Code: ags
// 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:

Code: ags
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.

Crimson Wizard

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
// 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.

Torchiest

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.

Torchiest

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."

Crimson Wizard

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.

Matti

I'm a bit confused about why you need that dialog at all. Can't you just put
Code: ags
cEgo.Say("My keys were in the door!");
in the hDoor_Interact script?

Torchiest

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
Code: ags
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.


SMF spam blocked by CleanTalk