Exit a dialog when all options are gone

Started by guga2112, Thu 19/11/2020 20:14:08

Previous topic - Next topic

guga2112

Hi everyone,
I have a dialog where the player needs to say all lines in a dialog - so it's basically a cutscene, but the player can choose the order in which the things get said.

Every time an option is chosen, it gets turned off. When only one line is left, the line is chosen automatically, and I like this. But when the last dialog script ends, the engine crashes. I suppose I'm doing something wrong.

What should I do? Is there a way of detecting when only one option (or none) is available and stop the dialog?

Khris

#1
Are you getting an error message with the crash?

Edit: Never mind, I can easily replicate this.
The error message is "all options have been turned off", and imo this should definitely auto-end the dialog, not crash the engine.

Here's a solution.

1. Add this to your global header / script
Code: ags
// global header
import void CheckEmpty(this Dialog*);

// global script
void CheckEmpty(this Dialog*) {
  for (int i = 1; i <= this.OptionCount; i++) {
    if (this.GetOptionState(i) == eOptionOn) return;
  }
  game.show_single_dialog_option = 0;
  this.SetOptionState(this.OptionCount, eOptionOn);
}


2. Add another option to the dialog, leave the text blank (it doesn't matter) and leave both Show and Say unchecked.

3. Right before each actual option's  return  dialog script command, after(!) you turn off the current option, insert
Code: ags
  this.CheckEmpty();


4. put  stop  as command for the last action.


NOTE: In order for AGS to not show the last option, the one that ends the dialog,  game.show_single_dialog_option  is set to 0. So don't forget to set the value to 1 again before a dialog where you do want to show the last option for the player to select.

guga2112

Thanks a lot! I actually came up with the very same workaround, but I was waiting for some more experienced member. I'm kinda proud now :-D

Anyway, except for the crash - which is of course something quite strange - I think dialogs should just end if no options are available. You usually have a last option, like "goodbye", so it's a rare case, but still...

Cassiebsg

There are those who believe that life here began out there...

Khris

 :-D

I was kinda surprised how well it worked, tbh. The dialog just ends, without a hitch.

Anyway, I hope this "bug" will be fixed with the next AGS version (cc: CW ;)), so this will hopefully just be a temporary workaround.

Crimson Wizard

How exactly the engine crashes, what is the error message etc?

Khris

Since apparently both of you have missed it:

Quote from: Khris on Thu 19/11/2020 20:37:46
The error message is "all options have been turned off", and imo this should definitely auto-end the dialog, not crash the engine.

guga2112

It hangs for a while and then:
"The game engine does not appear to have shut down properly. If the problem persists, post the problem on the Tech forum".

Shall I create a new topic for the problem?

Crimson Wizard

Quote from: Khris on Thu 19/11/2020 20:37:46
The error message is "all options have been turned off", and imo this should definitely auto-end the dialog, not crash the engine.

Oh I see. That should be easy to fix.

SMF spam blocked by CleanTalk