Jibble

Author Topic: How to do dialog with random answers  (Read 206 times)

How to do dialog with random answers
« on: 28 Feb 2021, 15:05 »
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?



Matti

Re: How to do dialog with random answers
« Reply #1 on: 28 Feb 2021, 16:39 »
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: Adventure Game Studio
  1. int r = Random(2);
  2. if (r == 0) cNPC.Say("story 1");
  3. if (r == 1) cNPC.Say("story 2");
  4. if (r == 2) cNPC.Say("story 3");
  5.  

Edit: Sorry, corrected Random with a capital R.
« Last Edit: 03 Mar 2021, 16:29 by Matti »

Re: How to do dialog with random answers
« Reply #2 on: 28 Feb 2021, 19:17 »
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: Adventure Game Studio
  1. @1
  2.  int r = random(2);
  3.  if (r == 0) cNPC.Say("story 1");
  4.  if (r == 1) cNPC.Say("story 2");
  5.  if (r == 2) cNPC.Say("story 3");
  6. return

Would you mind explaining a bit further?

Re: How to do dialog with random answers
« Reply #3 on: 28 Feb 2021, 19:22 »
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

Re: How to do dialog with random answers
« Reply #4 on: 28 Feb 2021, 23:37 »
Yes with the capital R it is working  :wink:

Thank you!