Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Wed 21/12/2016 12:02:46

Title: Conditionally go to another dialog [solved]
Post by: HandsFree on Wed 21/12/2016 12:02:46
F1 says you can use RUN_DIALOG_GOTO_PREVIOUS, RUN_DIALOG_RETURN and RUN_DIALOG_STOP_DIALOG.
But is there  a command to go to another dialog?

It looks like I can just use dDialog.Start(); within a dialog but then the goto_previous doesn't work.

Any ideas?
thanks
Title: Re: Conditionally go to another dialog
Post by: monkey0506 on Wed 21/12/2016 16:05:48
Using:

Code (ags) Select
@1
  if (cond)
goto-dialog 1
return


Generates a warning that the "return" will be ignored, but with 3.4.0, this works as expected, and the "goto-dialog" is, in fact, run conditionally.
Title: Re: Conditionally go to another dialog
Post by: HandsFree on Wed 21/12/2016 18:15:41
Actually, what I have is:

  if (cond1){
    do something
    goto-dialog 2
  }
  else{
    do something else
    // don't go to dialog 2
    return RUN_DIALOG_RETURN;
  }

Title: Re: Conditionally go to another dialog
Post by: monkey0506 on Thu 22/12/2016 04:14:13
Right, you won't be able to use braces on the condition, so you would need to rearrange it as:

Code (ags) Select
  if (!cond1) {
    // do something else
    // don't go to dialog 2
    return RUN_DIALOG_RETURN;
  }
  // since the "if" now contains a "return" statement, then the "else" block is implicit
  // for the following commands, cond1 is true
  // do something
goto-dialog 2


P.S. Use [code] and [/code] blocks around your code in the forums! ;)
Title: Re: Conditionally go to another dialog
Post by: Crimson Wizard on Thu 22/12/2016 07:21:37
Quote from: monkey0506 on Wed 21/12/2016 16:05:48
Using:

Code (ags) Select
@1
  if (cond)
goto-dialog 1
return


Generates a warning that the "return" will be ignored, but with 3.4.0, this works as expected, and the "goto-dialog" is, in fact, run conditionally.

I just want to elaborate, "goto-dialog" and other dialog-specific commands are simply substituted with corresponding general script commands before dialog script gets actually compiled. So in the end there are lines like dDialog1.Start(), and so on.
Title: Re: Conditionally go to another dialog
Post by: monkey0506 on Thu 22/12/2016 15:42:55
Using Dialog.Start() does break goto-previous (at least when Start is called from a dialog script). Using goto-dialog in a braceless condition does not.
Title: Re: Conditionally go to another dialog
Post by: Crimson Wizard on Thu 22/12/2016 21:24:57
Actually, I was wrong, it does not put explicit Dialog.Start there, but "return" statement with the number of next dialog, which triggers dialog run in the engine.

The reason I am mention this at all is that I want to elaborate to HandsFree why mixing dialog script commands and AGS Script commands work, even though they look unusual with difference in indentations.
Title: Re: Conditionally go to another dialog
Post by: HandsFree on Thu 22/12/2016 22:46:47
Ok, I got it working by reversing the condition. Thanks
But for my understanding: if I wanted to go to dialog1 under the condition, and to dialog2 under else, that's not possible, or is it?
Title: Re: Conditionally go to another dialog
Post by: Khris on Thu 22/12/2016 23:28:00
The original problem was about goto-previous not working if you use Dialog.Start(), but you can use a global pointer for that.
// global header
import Dialog *previousDialog;

// top of global script
Dialog* previousDialog;
export previousDialog;


Now use:
// dialog script
  previousDialog = dTheCurrentDialog;
  if (cond) dDialog1.Start();
  else dDialog2.Start();


In the other dialogs, simply use
  previousDialog.Start();
Title: Re: Conditionally go to another dialog [solved]
Post by: HandsFree on Fri 23/12/2016 23:51:50
Yes, thanks.
I already thought about using a variable to keep track of previous dialog. Just not a pointer.
Title: Re: Conditionally go to another dialog [solved]
Post by: monkey0506 on Sat 24/12/2016 00:05:07
Quote from: Crimson Wizard on Thu 22/12/2016 21:24:57it does not put explicit Dialog.Start there, but "return" statement with the number of next dialog, which triggers dialog run in the engine.

So the regular script equivalent of goto-dialog X is simply   return X;?

In fact, I just tested it, and that's precisely the case.

Code (ags) Select
  if (cond1) {
    // do something
    return 2; // goto-dialog 2
  }
  else {
    // do something else
    return RUN_DIALOG_RETURN; // don't go to dialog 2
  }