How to do dialog with random answers

Started by chip, Sun 28/02/2021 15:05:10

Previous topic - Next topic

chip

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

#1
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

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.

chip

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
@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?


chip

Yes with the capital R it is working  :wink:

Thank you!


SMF spam blocked by CleanTalk