Conditionally go to another dialog [solved]

Started by HandsFree, Wed 21/12/2016 12:02:46

Previous topic - Next topic

HandsFree

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

monkey0506

Using:

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

HandsFree

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;
  }


monkey0506

Right, you won't be able to use braces on the condition, so you would need to rearrange it as:

Code: ags
  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! ;)

Crimson Wizard

#4
Quote from: monkey0506 on Wed 21/12/2016 16:05:48
Using:

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

monkey0506

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.

Crimson Wizard

#6
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.

HandsFree

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?

Khris

The original problem was about goto-previous not working if you use Dialog.Start(), but you can use a global pointer for that.
Code: ags
// global header
import Dialog *previousDialog;

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


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


In the other dialogs, simply use
Code: ags
  previousDialog.Start();


HandsFree

Yes, thanks.
I already thought about using a variable to keep track of previous dialog. Just not a pointer.

monkey0506

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
  if (cond1) {
    // do something
    return 2; // goto-dialog 2
  }
  else {
    // do something else
    return RUN_DIALOG_RETURN; // don't go to dialog 2
  }

SMF spam blocked by CleanTalk