Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: chip on Sun 28/02/2021 15:05:10

Title: How to do dialog with random answers
Post by: chip on Sun 28/02/2021 15:05:10
Hello, I would like to get more variations in the dialogs, is it somehow possible to do a dialog like this:

Player say: "Tell me a story"

NPC say: "Random dialog picked out of some predefined sentences"

and how would I set this up?


Title: Re: How to do dialog with random answers
Post by: Matti on Sun 28/02/2021 16:39:24
You can use normal script in the dialog editor if you leave a space at the beginning of the line.

To do something like that you could use a variable and randomize it.

Code (ags) Select

int r = Random(2);
if (r == 0) cNPC.Say("story 1");
if (r == 1) cNPC.Say("story 2");
if (r == 2) cNPC.Say("story 3");


Edit: Sorry, corrected Random with a capital R.
Title: Re: How to do dialog with random answers
Post by: chip on Sun 28/02/2021 19:17:31
Hello, thanks for your reply, with that code I get an error message that says:

undefined symbol 'random'

This is how the dialog looks in my code:

Code (ags) Select
@1
int r = random(2);
if (r == 0) cNPC.Say("story 1");
if (r == 1) cNPC.Say("story 2");
if (r == 2) cNPC.Say("story 3");
return


Would you mind explaining a bit further?
Title: Re: How to do dialog with random answers
Post by: Crimson Wizard on Sun 28/02/2021 19:22:32
There was probably a typo, it's Random, with capital R.

Related article in the manual:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_General.html#random
Title: Re: How to do dialog with random answers
Post by: chip on Sun 28/02/2021 23:37:05
Yes with the capital R it is working  :wink:

Thank you!