Multiple Characters Talking Question

Started by DarkMasterOz, Thu 07/02/2013 16:14:03

Previous topic - Next topic

DarkMasterOz

My game features 3 playable characters, who you can control anytime you want and will say different things when interacting with people/objects.

What i'm having trouble with, is having different dialogs for each object, depending on who's in the room with you.

For example:
if BARRY is in the room on his own and looks at a car, he'll say "Nice Car".
But if JOHN is in the room with him, he'll say something else like "Can I drive your car?" and JOHN replies with "No."

Whenever i try to do that, it'll always say the "Nice Car" bit first, regardless if he's on his own or not.
This is the code i have.

function hCar_Look()
{
if (player == cBarry) {
  cBarry.Say("Nice car.");
}
  if (player.Room == cLee.Room)
  if (player == cBarry) {
  cBarry.Say("I like his car?.");
  if (player.Room == cLee.Room) cLee.Say("We should take it for a drive.");
  if (player.Room == cBarry.Room) cBarry.Say("I'll get John's permission first.");
}
if (player.Room == cJohn.Room)
if (player == cBarry) {
  cBarry.Say("Can I drive your car John?.");
  if (player.Room == cJohn.Room) cJohn.Say("No, no you can't.")


I'm not sure if that makes any sense or not, if it doesn't i'll try to explain a bit more clearly when i'm less tired.   :smiley:

Khris

#1
You need to use else or be more specific in your conditions.
The logic has to be spotless.

Here's how I'd handle the situation:
Code: ags
function hCar_Look() {

  if (player == cJohn) {
    player.Say("It's my car.");
    return;  // exit the function
  }

  // at this point, the player doesn't own the car and is either Lee or Barry
  bool owner_present = (cJohn.Room == player.Room);
  Character* other = cBarry;
  if (player == cBarry) other = cLee;
  bool other_present = (other.Room == player.Room); 

  if (owner_present) {
    player.Say("Can I drive your car?");
    cJohn.Say("No, no you can't.");
  }
  else {
    if (other_present) {
      player.Say("We should take it for a drive.");
      other.Say("I'll get John's permission first.");
    }
    else player.Say("Nice car.");
  }
}


Structuring it like this makes it a lot easier to add further lines or branches.

Dave Gilbert

Not related to the topic, but I noticed something and thought I'd give a warning. If you plan on using voice acting in your game and are also using multiple playable characters, do NOT use "player" with the "Say" command. Always use the character name. AGS uses the character name to determine which VO file to play, so if you use "player" it will royally screw it up. I have done this myself. :-D

MurrayL

Quote from: Dave Gilbert on Thu 07/02/2013 18:14:31
Not related to the topic, but I noticed something and thought I'd give a warning. If you plan on using voice acting in your game and are also using multiple playable characters, do NOT use "player" with the "Say" command. Always use the character name. AGS uses the character name to determine which VO file to play, so if you use "player" it will royally screw it up. I have done this myself. :-D

Yep - this is the reason subAtomic never got a VO pack. Since then, I've always scripted AGS games using cCharacterName.Say.

Khris

Is this due to the auto-number speech line function not knowing the value of player, or does this also happen if you number the lines yourself? Because the latter would classify as serious bug.

DarkMasterOz

Thanks for all the help, it works fine. I did change the player.say, to the name of the character though for good reasons brought up about the speech thing.  :smiley:

MurrayL

Quote from: Khris on Thu 07/02/2013 21:40:11
Is this due to the auto-number speech line function not knowing the value of player, or does this also happen if you number the lines yourself? Because the latter would classify as serious bug.

The game searches for the speech by the name of whoever the starting player character is, e.g. if cEgo is the player character, but you later change it to cBuddy, the game will still look for speech files named EGOxxx.wav.

SMF spam blocked by CleanTalk