Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: General on Sat 23/02/2008 08:57:08

Title: Dialog Question - Random Response
Post by: General on Sat 23/02/2008 08:57:08
Let's say I'd let my main character talk to a man in a town and I have a Dialog Option:
"What can you tell me about the town?"
And now I want the man to respond randomly:
"We have a pretty nice pub. Check it out!"
or
"Try visiting the local park. It's quite nice."
and so on, and so on.
Is there any way to do that?
I thought about making a second, third etc. dialog-script, but that would mean, that I'd need to copy all other available options in those scripts too (for example "Hello, how are you?", "What do you know about X?" etc.). That looks pretty much like a major headache, if the conversation gets a bit more complex.
And if there is no way to make it random, is there at least a way to change the answers?
(First he tells me about the pub, then the park, then the inn etc. etc. and then about the pub again and so on)??
Any suggestions?
Title: Re: Dialog Question - Random Response
Post by: Radiant on Sat 23/02/2008 11:02:17
Use run-script in the dialog, and then put this in your main script:


function dialog_request (int num) {
  int are = Random (3);
  if (num == 1) {
    if (are == 0) character[SOMEBODY].Say ("Hello");
    if (are == 1) character[SOMEBODY].Say ("bye");
    if (are == 2) character[SOMEBODY].Say ("greetz");
    if (are == 3) character[SOMEBODY].Say ("huh?");
  }
}




(edit) Heh. Turns out you can't name a variable "R" in a code block without having it renamed "are"...
Title: Re: Dialog Question - Random Response
Post by: General on Sat 23/02/2008 15:48:21
Big thx!
That cleared my head and gave me inspiration for new stuff!
Ah, I love this program.
Title: Re: Dialog Question - Random Response
Post by: Akatosh on Sun 24/02/2008 17:29:59
If you're going to have that a "generic reply", you could also do something like this:


String genresponse[4];
genresponse[0]="Heya";
genresponse[1]="Whuzzup";
genresponse[2]="Eh?";
genresponse[3]="Portal reference!";
//and so on. you get the idea.

function dialog_request (int num) {
  if (num == 1) character[SOMEBODY].Say("%s",genresponse[Random(3)];
}