Making character say stuff and object appear

Started by Mr_Threepwood, Tue 27/09/2005 02:06:37

Previous topic - Next topic

Mr_Threepwood

Im trying to get my character to say different things depending on when he looks at the hotspot, a tree in this case.

Code: ags

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

Code: ags

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?
I am a mighty pirate

strazer

Quote from: Mr_Threepwood on Tue 27/09/2005 02:06:37
Code: ags

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:

Code: ags

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.

Mr_Threepwood

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?
I am a mighty pirate

Janik

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].
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!

strazer

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.

Gilbert

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++;
}

strazer

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

Code: ags

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


or, in the upcoming AGS v2.71:

Code: ags

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

Gilbert

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.

monkey0506

Quote from: strazer on Tue 27/09/2005 06:49:05
Code: ags

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

Now strazer, that's just silly.

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


:=

SMF spam blocked by CleanTalk