Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ray on Wed 25/07/2018 20:47:23

Title: Character need to say different, but relevant phrases...
Post by: Ray on Wed 25/07/2018 20:47:23
Hi,
I'm working on my first AGS adventure game and would like to understand a couple of things about how much flexibility I have with 'Say' function.
1. When player clicks on the hotspot and my character is going to say something, is it possible to make his phrase to be randomly choose from 2,3...N relevant phrases? For example, when player clicks on window of spaceship, my character would say something like: "This is uncharted space, I never was here." But if player clicks on same window again, the character may say something different, like : "I do not know what to expect - this is an uncharted territory." I just would like it sounds more natural than repeating the same phrase over and over again.
2. Is it possible for AGS to read texts from the external file, like .txt to keep all the characters phrases in one place for correction and revisions?

Thanks in advance!
Title: Re: Character need to say different, but relevant phrases...
Post by: Slasher on Wed 25/07/2018 20:58:29
You could make an int and have it Randomize replies..

Here I have it in a function within a module if reply to anything.
Code (ags) Select

function Inv_Random()
{
int  Rand=Random(2);
if(Rand==0)
cBert.Say("Do I look like some kind of pilchard?");   
else if(Rand==1)
cBert.Say("Err. That's utterly pointless.");   
else if(Rand==2)
cBert.Say("That's daft.");
}


Call it with 
Code (ags) Select

Inv_Random();


else just do this for each object/hotspot within a function

Code (ags) Select

int  Rand=Random(2);
if(Rand==0)
cBert.Say("Do I look like some kind of pilchard?");   
else if(Rand==1)
cBert.Say("Err. That's utterly pointless.");   
else if(Rand==2)
cBert.Say("That's daft.");



These are examples only..

Title: Re: Character need to say different, but relevant phrases...
Post by: Snarky on Wed 25/07/2018 21:01:57
1. Yes, this is possible. The easiest way is probably to use the MultiResponse module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=27947.0), which provides the function Multi.SRandom() that does pretty much exactly this. Without testing it myself, I think you would write it like:

Code (ags) Select
  cBert.Say(Multi.SRandom("Do I look like some kind of pilchard?>Err, that's utterly pointless.>That'd be daft."));

And it would randomly use one of the lines separated by > signs.

2. It's possible, but it's not recommended. You're better off using the Speech Center plugin (http://www.adventuregamestudio.co.uk/forums/index.php?topic=45622.0), which collects all the dialog in one convenient editor inside the AGS editor.[/code]
Title: Re: Character need to say different, but relevant phrases...
Post by: Slasher on Wed 25/07/2018 21:09:31
Snarky: That module is no longer available...
Title: Re: Character need to say different, but relevant phrases...
Post by: Ray on Wed 25/07/2018 21:20:24
Thanks a lot for suggestions and examples :) Will keep it in mind.
I really was hoping there is a relatively easy way, like one with  MultiResponse module...

Speech Center Plugin sounds very handy - definitely will use it.

Thanks again to you both for prompt respond!
Cheers
Title: Re: Character need to say different, but relevant phrases...
Post by: Snarky on Wed 25/07/2018 21:24:23
Quote from: Slasher on Wed 25/07/2018 21:09:31
Snarky: That module is no longer available...

It is if you read the thread to the end. (And in general, when the download for a module is down, you can just ask. Usually someone has it.)
Title: Re: Character need to say different, but relevant phrases...
Post by: Ray on Sat 28/07/2018 22:51:40
I'd like to have some sort of algorithm for phrases my main character says...
For example, I have five phrases he says when he "look" at window; so for first five "looks" at window I'd like him to say one of 5 phrases in strict direction: phrase 1,2,3,4,5 to introduce the subject to player, but if my character "look" at window 6 and more time I'd like same 5 phrases to be displayed in random order.

Should I go with the If-Else or there is some more efficient way to do it?
Thank you!
Title: Re: Character need to say different, but relevant phrases...
Post by: Retro Wolf on Sun 29/07/2018 00:46:02
hVan is just the name of a hotspot in my game.

Code (ags) Select
int count;
function hVan_Look()
{
  int saywhat;
  count++;
 
  if (count <= 5) {saywhat = count;}
  else {saywhat = (1 + Random(4));}//1+4 = 5
 
  switch (saywhat)
  {
    case 1:
      player.Say("one potato");
    break;
    case 2:
      player.Say("two potato");
    break;
    case 3:
      player.Say("three potato");
    break;
    case 4:
      player.Say("four potato");
    break;
    case 5:
      player.Say("five potato");
    break;
  }
}
Title: Re: Character need to say different, but relevant phrases...
Post by: Ray on Sun 29/07/2018 03:47:23
Thank you Retro Wolf :)
Looks great!
Title: Re: Character need to say different, but relevant phrases...
Post by: Retro Wolf on Tue 31/07/2018 14:06:48
No problem mate, good luck with the project.
Title: Re: Character need to say different, but relevant phrases...
Post by: Insight-Out on Fri 03/08/2018 14:15:18
I was about to ask that too... Thanks a lot!!
Title: Re: Character need to say different, but relevant phrases...
Post by: Insight-Out on Mon 06/08/2018 13:56:32
How about different characters saying different things on the same action, that's possibly already asked, I apologise in advance...
Title: Re: Character need to say different, but relevant phrases...
Post by: Crimson Wizard on Mon 06/08/2018 14:08:08
Quote from: Insight-Out on Mon 06/08/2018 13:56:32
How about different characters saying different things on the same action, that's possibly already asked, I apologise in advance...

How to do something depending on which character is player's right now:
Code (ags) Select

if (player == cBob)
    player.Say("I am Bob.");
else if (player == cJane)
    player.Say("I am Jane.");
Title: Re: Character need to say different, but relevant phrases...
Post by: Insight-Out on Tue 07/08/2018 12:59:54
Thank you so much Crimson Wizard!!
Title: Re: Character need to say different, but relevant phrases...
Post by: HarmHero on Sun 12/03/2023 18:10:11
I had to do this when I wanted the character to say something when he approached the edge of a Walkable Area, in this case the sea:

function region1_WalksOnto()
{
#define i 5 //total messages
String message[i];
message[0] = "Nope, I can't stand salty water.";
message[1] = "I don't want wet feet!";
message[2] = "Not going to ruin my shoes man...";
message[3] = "No way, what if there are sharks?";
message[4] = "Hmmm, I don't think I can swim...";
int index = Random(i - 1);
player.Say(message[index]);
}
Title: Re: Character need to say different, but relevant phrases...
Post by: Khris on Sun 12/03/2023 21:42:17
You can also write functions for this:
String _message[20];
int _message_count;

void Add(String message) {
  _message[_message_count] = message;
  _message_count++;
}

void Clear() {
  _message_count = 0;
}

void SayRandom(this Character*) {
  if (_message_count == 0) return;
  this.Say(message[Random(_message_count - 1)]);
}

Now you can do:
function region1_WalksOnto()
{
  Clear();
  Add("Nope, I can't stand salty water.");
  Add("I don't want wet feet!");
  Add("Not going to ruin my shoes man...");
  Add("No way, what if there are sharks?");
  Add("Hmmm, I don't think I can swim...");
  player.SayRandom();
}

edit: code fixed