Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: guga2112 on Thu 19/11/2020 20:14:08

Title: Exit a dialog when all options are gone
Post by: guga2112 on Thu 19/11/2020 20:14:08
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?
Title: Re: Exit a dialog when all options are gone
Post by: Khris on Thu 19/11/2020 20:37:46
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) Select
// 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) Select
  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.
Title: Re: Exit a dialog when all options are gone
Post by: guga2112 on Thu 19/11/2020 21:20:00
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...
Title: Re: Exit a dialog when all options are gone
Post by: Cassiebsg on Thu 19/11/2020 21:25:24
I normally just use option 2.  ;)
Title: Re: Exit a dialog when all options are gone
Post by: Khris on Thu 19/11/2020 21:27:25
 :-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.
Title: Re: Exit a dialog when all options are gone
Post by: Crimson Wizard on Fri 20/11/2020 00:58:58
How exactly the engine crashes, what is the error message etc?
Title: Re: Exit a dialog when all options are gone
Post by: Khris on Fri 20/11/2020 09:01:52
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.
Title: Re: Exit a dialog when all options are gone
Post by: guga2112 on Fri 20/11/2020 09:40:18
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?
Title: Re: Exit a dialog when all options are gone
Post by: Crimson Wizard on Fri 20/11/2020 10:38:46
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.