Character need to say different, but relevant phrases...

Started by Ray, Wed 25/07/2018 20:47:23

Previous topic - Next topic

Ray

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!

Slasher

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

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

Inv_Random();


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

Code: ags

 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..


Snarky

1. Yes, this is possible. The easiest way is probably to use the MultiResponse module, 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
  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, which collects all the dialog in one convenient editor inside the AGS editor.[/code]

Slasher


Ray

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

Snarky

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.)

Ray

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!

Retro Wolf

hVan is just the name of a hotspot in my game.

Code: ags
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;
  }
}

Ray

Thank you Retro Wolf :)
Looks great!

Retro Wolf


Insight-Out


Insight-Out

How about different characters saying different things on the same action, that's possibly already asked, I apologise in advance...

Crimson Wizard

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

if (player == cBob)
    player.Say("I am Bob.");
else if (player == cJane)
    player.Say("I am Jane.");


HarmHero

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:

Code: ags
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]);
}

Khris

You can also write functions for this:
Code: ags
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:
Code: ags
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

SMF spam blocked by CleanTalk