Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: dscarmon on Wed 14/04/2021 18:28:26

Title: How to Perform action on dialog selection
Post by: dscarmon on Wed 14/04/2021 18:28:26
Hi All,
I am very new to AGS, and I am finding it to be very intuitive and flexible!
The challenge I am trying to overcome is this:  I need the character to take an action immediately after selecting dialog option 1 (code below). The way it is working now, the action will not happen until I click on the character again. I suspect this is because of my usage of HasOptionBeenChosen, but after looking at all the dialog options in the manual, I didn't see another way to do this. Please let me know if I need to add more context or if I am missing something. Thank you!

Code (ags) Select

function cOldBen_Interact()
{
if (bendialog == 10)
  {
  }
//start the dialog
    dDialog1.Start();
    bendialog = 1;
    Display("The variable is %d",bendialog);
    dKillorSpare1.Start();

//When option 1 is chosen, set variables, walk to select xy, play animations
if (dKillorSpare1.HasOptionBeenChosen(1))
  {
    StopDialog();
    bendialog = 2;
    benkill = 1;
    Display("Kill is %d",benkill);
    cGunslinger.Walk(705, 534, eBlock, eWalkableAreas);
    cGunslinger.Animate(7, 10, eOnce);
    cOldBen.Animate(8, 8, eOnce);
    Display("The variable is %d",bendialog);
   
  }
Title: Re: How to Perform action on dialog selection
Post by: Khris on Wed 14/04/2021 19:06:18
First of all: starting a dialog gets queued and will only run after the current function has finished (please make sure to always read the manual entries for commands in their entirety).

Secondly, you can run standard script commands right inside your dialog scripts; all you need to do is to indent them by at least one space.

Which means that  dDialog1.Start();  is the only command you should have in there, and move all that happen during the dialog into the dialog script.
Title: Re: How to Perform action on dialog selection
Post by: dscarmon on Thu 15/04/2021 01:42:57
Much appreciated! I must have missed that, thank you.