Background Speech - Who's talking?

Started by Bernie, Wed 01/09/2004 19:45:49

Previous topic - Next topic

Bernie

Is there a way to determine if a certain character is currently background talking, or is it possible to track it with variables somehow?

Thanks in advance~

Scorpiorus

#1
Yeah, you can have an array (each element corresponding to each character) and write overlay numbers there, so that later you can check if an overlay is valid (thus checking if a character is talking):

main global script:
#define AGS_CHARACTER_MAX 150
int bank[AGS_CHARACTER_MAX];

function Reset(int overlay) {

   int i=0;
   while (i<AGS_CHARACTER_MAX) {
      if (bank[ i ]==overlay) bank[ i ]=0;
      i++;
   }
}

function DisplaySpeechBackgroundEx(int CharID, string speech) {
   
   int overlay = DisplaySpeechBackground(CharID, speech);
   Reset(overlay);
   bank[CharID] = overlay;
}

function IsCharacterSpeeching(int CharID) {
   return IsOverlayValid(bank[CharID]);
}


Ex:

DisplaySpeechBackgroundEx(EGO, "blah");
if (IsCharacterSpeeching(EGO)) Display("EGO's talking.");

Bernie

Great, thanks! :D This works very well indeed!

Thanks to you, I finally found out how to do arrays in AGS, I've been trying to do that all day.
Strange that I couldn't find anything about them in the manual. Either I didn't look thoroughly enough, or they're just not covered in it.

Anyway, you'll now be mentioned in my games' credits. Hooray for you! ^^


EDIT - A small question, should be simple:

In repeatedly execute, I want a while loop that subtracts 1 from an inventory item from every character every loop.
I've done this, assuming there's 100 characters:

int i=0;
while (i<100) {character.inv[11]=character.inv[11]-1;i++;}

But it doesn't seem to work right. Any ideas?

EDIT 2 - Nevermind, got it to work :)

Scorpiorus

#3
You are welcome :)

The info on declaring arrays is not in the manual because it's an unofficial feature. Despite that fact they appear to work fine, moreover AGS uses arrays (and also structs) for official things: character[xxx].inv[xxx] as you know; so it's fairly reliable.
Just don't get out of the bounds operating with arrays, like:

int myArray[10];

myArray[100] = 1;
myArray[10] = 2;
myArray[-1] = 3;


but this is fine:
myArray[ 0 ] = 1;
myArray[1] = 2;
...
myArray[8] = 3;
myArray[9] = 4;

Bernie

Thanks, they're gonna be very useful! :)
So, what's a struct do?

Pumaman

The main reason arrays are undocumented is because arrays of strings don't work properly, and would really be an essential feature if arrays were to be officially supported.

Scorpiorus

Quote from: Bernie on Thu 02/09/2004 10:07:28So, what's a struct do?

Think of this like it's a user-defined custom type which you can define and you then can declare variables of that type. It's not a simple basic type as 'int' because it has a more complex structure (hence the name struct). It's like a name joining together other variables of basic types (mostly int). 'game' is a typical instance of struct. Those joined variables are usually called 'fields' or 'member variables' and can be accessed with a dot ('.') operator:

Example:[/u]

game.total_score
game.anim_background_speed
game.disable_antialiasing
game.sierra_inv_color
game.skip_display
game.text_align
game.text_shadow_color
game.text_speed higher
game.used_mode

...where:

game -> is an instance of struct;
total_score -> is one of the game's fields;



You can declare your own structs but they, as well as arrays, are not officially supported because it's normally not allowed to include 'string' fields into structs.[/i]



Example of declaring and using of structs:

// main global script file

// First we must declare a struct.
// MONEY_TYPE will be a struct name, i.e. will be a new type name.
// gold, silver and copper are struct fields, all of int type:

struct MONEY_TYPE {

   int gold;
   int silver;
   int copper;
};


// so we only defined a type but have not yet declared any variables
// let's do that:


MONEY_TYPE RogerMoney;Ã,  // MONEY_TYPE is a type and RogerMoney is a name of a variable we are declaring (just like 'int x;')

// after have declared a variable of MONEY_TYPE type we can access its fields:

RogerMoney.gold = 1;
RogerMoney.silver = 10;
RogerMoney.copper = 100;

if (RogerMoney.gold < 10) Display("You can't afford to buy a chain armour!");


Notice the difference between a struct and an instance of struct:
MONEY_TYPE is a struct (i.e. a type)
and RogerMoney is an instance of the MONEY_TYPE struct (i.e. a variable).



You can also have arrays of structs:

MONEY_TYPE CharactersMoney[150]; // just like ordinary arrays

CharactersMoney[EGO].gold = 100;
CharactersMoney[BART].gold = 10;

etc.


Nothing prevents you from using arrays as fields inside the struct:

struct[/color] MONEY_TYPE {

   int[/color] gold;
   int[/color] silver;
   int[/color] copper;
   
   int[/color] xxx[100];
};

MONEY_TYPE RogerMoney;
MONEY_TYPE CharactersMoney[150];


RogerMoney.xxx[9] = 1;
CharactersMoney[EGO].xxx[10] = 3;


Buy the way, AGS' character[] is an array of structs:
character[EGO].inv[20] = 1;
character[EGO].activeinv = 10;
while (character[MAN].walking == 0) Wait(1);
See?


Structs are very useful if, for example, you make an RPG and need to assort and manage characters skills. Structs make it easy and comfortable:

// declaring a STATS struct:
struct[/color] CHARACTER_STATS_TYPE {

   int[/color] health;
   int[/color] stamina;
   int[/color] mana;

   int[/color] strength;
   int[/color] agility;
   int[/color] vitality;
   int[/color] intelligence;
};

// declaring an array of CHARACTER_STATS_TYPE:
CHARACTER_STATS_TYPE CharStats[150];


// using it:

CharStats[EGO].health = 100;
CharStats[EGO].strength = 11;

CharStats[ENEMY].health = 70;

if (CharStats[EGO].strength > 10) CharStats[ENEMY].health = CharStats[ENEMY].health - 1;

etc.

Hope it helps :)

monkey0506

Wow! This is awe inspiring!



















AWE!


This is really cool!

Bernie

Haha, sure is! Another very useful hidden feature, thanks! :)

TheSaint

Quote from: Bernie on Wed 01/09/2004 19:45:49
Is there a way to determine if a certain character is currently background talking, or is it possible to track it with variables somehow?

Thanks in advance~

what exactly does he mean with background speech?

Privateer Puddin'

From the manual

Similar to DisplaySpeech, except that this function returns immediately and the game continues while the character is talking. This allows you to have characters talking in the background while the player does other things. Note that the character's talking animation is not played if this function is used.

monkey0506

Wow... Way to not read the manual The saint... Great job. And as if you couldn't figure it out, you could animate the character while he's talking in the background, and release him when he's not so it looks like he's talking. A classic example of this is the shop keeper on Melee Island in The Secret of Monkey Island. "Are you waiting for me to fall asleep?"

SMF spam blocked by CleanTalk