Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mr_Threepwood on Tue 27/09/2005 02:06:37

Title: Making character say stuff and object appear
Post by: Mr_Threepwood on Tue 27/09/2005 02:06:37
Im trying to get my character to say different things depending on when he looks at the hotspot, a tree in this case.


sectionstart hotspot1_aÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot1_a() {
Ã,  // script for Hotspot 1 (tree): Look at hotspot

int x=1;

if (x==1){
Character[EGO].Say("Its a tree");


x+=1
}else if(x==2){
Character[EGO].Say("I think I can see something in the tree");
x+=1
}else if (x==3){
Character[EGO].Say("Maybe i should try to get it...");
x+=1
}else if (x>3){
Character[EGO].Say("Try USING the tree, ffs");
}
}


also this isnt working


Object[0].Visible=true; 


I cant figure out why, I did what was in the help file.
and it says variableÃ,  '[' is already defined, what am I doing wrong?
Title: Re: Making character say stuff and object appear
Post by: strazer on Tue 27/09/2005 03:05:05
Quote from: Mr_Threepwood on Tue 27/09/2005 02:06:37

sectionstart hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot1_a() {
  // script for Hotspot 1 (tree): Look at hotspot

  int x=1;

  //...


At the moment you define the variable inside the function, so it gets destroyed when the function ends.
Everytime the function runs, the variable gets re-created with a value of 1.

Place variable definitions outside of any functions to make the variable a static (global) one. This way, it retains its value:


int x=1;

sectionstart hotspot1_a  // DO NOT EDIT OR REMOVE THIS LINE
function hotspot1_a() {
  // script for Hotspot 1 (tree): Look at hotspot

  //...


And it's
object[0].Visible = true;
AGS is case-sensitive.
Title: Re: Making character say stuff and object appear
Post by: Mr_Threepwood on Tue 27/09/2005 04:13:50
Thanks for the reply, I got both of them working, all because of the stupid upper cases, I cant believe I did that mistake even after checking the API thing.  Ive done programming for 3 years now I should have notied that, arg.  One more quick question, is the Character[charName].Say("String") the way you would normally go about making a character say something if you want them to say different things each time they look at something?  Or would you normally use the game display method as long as you have the option to display messages as speech?
Title: Re: Making character say stuff and object appear
Post by: Janik on Tue 27/09/2005 04:46:59
I'd say that's a personal preference thing. For me, the script is a lot faster than the interaction editor, since you don't need to define a message separately. If you use Say instead of Display everywhere, it means you can use a normal text dialog whereas with the "Say everything" option, you can't.

By the way, you can use

player.Say

or

cCharname.Say

equivalently. Look in the character pane, the "Script O-name" is defined there and is a shortcut to character[charName].
Title: Re: Making character say stuff and object appear
Post by: strazer on Tue 27/09/2005 04:55:09
Quote from: Mr_Threepwood on Tue 27/09/2005 04:13:50is the Character[charName].Say("String") the way you would normally go about making a character say something if you want them to say different things each time they look at something?

First up, to clarify:
For backwards-compatibility reasons you can still do

  character[CHARNAME].Say("Blah"); // i.e. character[ROGER].Say("Blah");
or
  character[NumberOfCharacterAkaID].Say("Blah"); // i.e. character[2].Say("Blah");

but the recommended way since AGS v2.7 is
  cCharacterscriptname.Say("Blah"); // i.e. cRoger.Say("Blah");

You can also use
  player.Say("Blah");
if you want the player character to say something, regardless of what character that may be at the moment (think multiple player characters like in Day Of The Tentacle).

Quote from: Mr_Threepwood on Tue 27/09/2005 04:13:50Or would you normally use the game display method as long as you have the option to display messages as speech?

That totally depends on you. Both ways work, see LucasArts / Sierra. Personally I prefer the LucasArts way.
Title: Re: Making character say stuff and object appear
Post by: Gilbert on Tue 27/09/2005 05:13:16
Quote from: strazer on Tue 27/09/2005 04:55:09
First up, to clarify:
For backwards-compatibility reasons you can still do

Ã,  character[CHARNAME].Say("Blah"); // i.e. character[ROGER].Say("Blah");
or
Ã,  character[NumberOfCharacterAkaID].Say("Blah"); // i.e. character[2].Say("Blah");

but the recommended way since AGS v2.7 is
Ã,  cCharacterscriptname.Say("Blah"); // i.e. cRoger.Say("Blah");

To clarify more, it's not only for backward compatibility reasons, it's also for more advanced programming use, like for example:
int i=1;
while (i<=8){
  character.Say("I'm number %d!", i);
  i++;
}
Title: Re: Making character say stuff and object appear
Post by: strazer on Tue 27/09/2005 06:49:05
True, I didn't mention that as not to confuse people any more than I probably already did. :)

Btw, for anyone stumbling across Gilbot's code, contrary to the Display function, Character.Say allows only a single parameter, so you would have to do


  //...
  string tempstr;
  StrFormat(tempstr, "I'm number %d!", i);
  character[i].Say(tempstr);
  //...


or, in the upcoming AGS v2.71:


  //...
  String tempstr = String.Format("I'm number %d!", i);
  character[i].Say(tempstr);
  //...
Title: Re: Making character say stuff and object appear
Post by: Gilbert on Tue 27/09/2005 09:38:27
Hehe yeah my fault, as I didn't check the manual. But anyway, it's an example how that array format can be VERY useful.
Title: Re: Making character say stuff and object appear
Post by: monkey0506 on Wed 28/09/2005 14:01:21
Quote from: strazer on Tue 27/09/2005 06:49:05
  //...
  String tempstr = String.Format("I'm number %d!", i);
  character[i].Say(tempstr);
  //...

Now strazer, that's just silly.

character[i].Say(String.Format("I'm number %d!", i));

:=