Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Joseph on Mon 24/08/2009 22:55:24

Title: Function in a dialog (SOLVED)
Post by: Joseph on Mon 24/08/2009 22:55:24
Yeeehawww! Howdy padnah's!

I got this to work inside a dialog:


// Dialog script file
@S  // Dialog startup entry point
EGO: "Excuse me...!"
ROGER: "Hey, whats up!"
return
@1
 cEgo.SpeechView = 15;
 cEgo.BlinkView = 16;
ROGER: "Im Roger."
 cRoger.Name = "Roger";
EGO: "Where's the can?"
ROGER: "...yeah, its down the hall..."
 cEgo.SpeechView = 5;
 cEgo.BlinkView = 6;
return
@2
ROGER: "Bye."
stop

When I call to change the speech + blink views, no problemo! BUT...if I try to change the speech font, it doesnt work. I tried placing Game.SpeechFont = eFontDialogOptions; into my dialog above...doesnt work!

SO...I believe (from the manual, if I understand), I made a function and placed it into my global script asc. I tried calling that inside my dialog, but that didnt work either :

function changeSpeechFont()
{
  Game.SpeechFont = eFontDialogOptions;
}

(I then placed "changeSpeechFont;" inside the dialog above.

What am I missing? Im sure its something simply small...


Ps: And I didnt quite understand this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=38171.0
Title: Re: Function in a dialog
Post by: Khris on Mon 24/08/2009 23:13:34
You need to call your functions with () at the end:

changeSpeechFont();

What error messages did you get?
Did you define eFontDialogOptions yourself?
What happens if you try
Game.SpeechFont = eFontFont1;
?
Title: Re: Function in a dialog
Post by: Joseph on Tue 25/08/2009 00:03:55
Hi KhrisMUC,

Ok, I placed this line in GlobalScript.ash:

import function changeSpeechFont();


I placed this line in GlobalScript.asc:

function changeSpeechFont()
{
 Game.SpeechFont = eFontDialogOptions;
}

The I tried calling it in my dialog like this:

// Dialog script file
@S  // Dialog startup entry point
EGO: "Excuse me...!"
ROGER: "Hey, whats up!"
return
@1
 cEgo.SpeechView = 15;
 cEgo.BlinkView = 16;
changeSpeechFont();    <------------------------placed it here
ROGER: "Im Roger."
 cRoger.Name = "Roger";
EGO: "Where's the can?"
ROGER: "...yeah, its down the hall..."
 cEgo.SpeechView = 5;
 cEgo.BlinkView = 6;
return
@2
ROGER: "Bye."
stop

I get this error:

Dialog 0(18): Unknown command: changespeechfont(). The command may require parameters which you have not supplied.

In my fonts, I have 6 in total so far. I named my 3rd font (4th if you include Font0) "3: DialogOptions". Its scriptID is eFontDialogOptions.

It is a font I imported myself (a TTF).


I tried inserting "Game.SpeechFont = eFontFont1;" as your suggestion in the dialog, however I get this error:

Dialog 0(19): Unknown command: game.speechfont = efontfont1. The command may require parameters which you have not supplied.

Thanks for your help, amigo :)


EDIT:

I tried this, and this works (but Id much rather do this in a simpler way and not have to manually place these lines each time I want to change the font of someone speaking)...seems like I NEED to place a "tab" before the script line, like this:


@2
  Game.SpeechFont = eFontDialogOptions;               <--------tabbed
ROGER: "blah blah blah."
  Game.SpeechFont = eFontSpeech;                          <--------tabbed
EGO: "blah blah blah."
  Game.SpeechFont = eFontDialogOptions;               <--------tabbed
ROGER: "blah blah blah."
  Game.SpeechFont = eFontSpeech;                         <--------tabbed
return

Now, everytime "Roger" speaks, its speech font is set to eFontDialogOptions...and evertime "Ego" speaks is set back to eFontSpeech.

What would be the best way for me to accomplish this, without having to type in those lines after each dialog line?
Title: Re: Function in a dialog
Post by: Joseph on Tue 25/08/2009 15:52:35
Im double-posting, I know...I already edited my last post, so if I did it again...it could be confusing!

Ok, so I tried

function repeatedly_execute_always()
{
  //Set character fonts and speech views
  if (cRoger.Speaking)
  {
      SetTextWindowGUI (16);
      Game.SpeechFont = eFontRogerSpeech;

  }
  if (cEgo.Speaking)
  {
      SetTextWindowGUI (7);
      Game.SpeechFont = eFontEgoSpeech;

  }

}

It works...BUT...since I have an "if" statement, it will only change the speechfont after the character has already spoken once, so that the next time the character speaks, it changes OK.

Is there a way to make it so it checks the dialog script and changes the font BEFORE the player speaks (not to check IF  the player speaks).

Know what I mean?
Title: Re: Function in a dialog
Post by: AdamM on Tue 25/08/2009 22:36:51
How does the idea of a custom Say function strike you? (Bear with me here as I've never used extender functions before)


function SayCustomFont(this Character*, string message) {

if (this == cEgo) {Game.SpeechFont = eFontEgoSpeech;}
else if (this == cRoger) {Game.SpeechFont = eFontRogerSpeech;}
else ...

//etc. for every character in the game that you want to use a custom font

this.Say(message);
}


Then you can just ditch the standard dialog formatting altogether, and use:

@1
cEgo.SayCustomFont("Hi, I'm using a custom font.")
cRoger.SayCustomFont("So am I! My font is different to yours!")
return
Title: Re: Function in a dialog
Post by: Joseph on Wed 26/08/2009 02:31:48
Hi AdamM,

I put this in GlobalScript.asc:

function SayCustomFont(this Character*, string message)
{
if (this == cEgo)
{
   Game.SpeechFont = eFontEgoSpeech;
}
else if (this == cRoger)
{
   Game.SpeechFont = eFontRogerSpeech;
}
// else ...

//etc. for every character in the game that you want to use a custom font

this.Say(message);
}

And this in my dialog:

// Dialog script file
@S  // Dialog startup entry point
//EGO: "Excuse me...!"
//ROGER: "Hey, whats up!"
  cEgo.SayCustomFont("Hi, I'm using a custom font.");
  cRoger.SayCustomFont("So am I! My font is different to yours!");
return

However, I get this error:

Dialog 0(5): Error (line 5): '.SayCustomFont' is not a public member of 'Character'. Are you sure you spelt it correctly (remember, capital letters are important)?

What did I do wrong?

I feel we're gettin' close though!
Title: Re: Function in a dialog
Post by: skuttleman on Wed 26/08/2009 03:45:45
I think you need this line in GlobalScript.ash


import function SayCustomFont(this Character*, string message);


That should make the function accessible to the dialog scripts.
Title: Re: Function in a dialog
Post by: Joseph on Wed 26/08/2009 04:36:32
Arrr!! Skuttleman mee boy!

Ok, did that, one step closer :)

Now me gets this little DoOzee:

Dialog 0(5): Error (line 5): Type mismatch: cannot convert 'const string' to 'string'

I'll continue scratching me head on this one...

PS: Whats a "const string"...construct string? Ill look it up to see if I can find out what this is.
Title: Re: Function in a dialog
Post by: Gilbert on Wed 26/08/2009 04:41:33
Should change the 'string' to 'String' (I wonder whether the obsoleted 'string' type could ever be used as custom funcion parameters).

So, in the declaration of the function:

function SayCustomFont(this Character*, String message)
{


And in the header:

import function SayCustomFont(this Character*, String message);
Title: Re: Function in a dialog
Post by: Joseph on Wed 26/08/2009 04:59:20
Gilbet V7000a....holy. (insert expletive here)!!

Wowza...its works now...man, thanks to you all...

EDIT: Ive got one little prob though since the last time I posted (doin' tests and whatnot)...check this image out---->


(http://www.2dadventure.com/ags/options000.gif)

If I have the option "say" at the dialog options,  when the main character says the question, the SayCustomFont function doesnt know whos speaking, so it just uses the last font that was previously displayed...

How could I work around this? What function does AGS use to display the question you wrote in the options? (if it was character.say, wouldnt the SayCustomFont function pick it up?)


Title: Re: Function in a dialog
Post by: Joseph on Fri 28/08/2009 03:46:18
Oh, and I love turtles.

OKTHANKSBYE
Title: Re: Function in a dialog
Post by: Khris on Fri 28/08/2009 05:57:16
Uncheck Say and copy the option text to the dialog script.
Title: Re: Function in a dialog
Post by: Joseph on Fri 28/08/2009 14:06:38
Quote from: KhrisMUC on Fri 28/08/2009 05:57:16
Uncheck Say and copy the option text to the dialog script.

Hi Khris,

You know, I actually thought of doing that...I guess I was thinking "nah, Im sure theres a way to do it within the custom script"...bah, I guess sometimes we just dont have to make things complicated for ourselves!

Aight...Im doin' it that way, save myself some trouble :)
Title: Re: Function in a dialog
Post by: monkey0506 on Fri 28/08/2009 15:26:43
Just so you know you can prevent yourself having to retype the option text by using Dialog.GetOptionText. Uncheck the "Say" boxes as Khris said and then do:

@1
 player.SayCustomFont(dDialogname.GetOptionText(1));
// blah blah blah
@2
 player.SayCustomFont(dDialogname.GetOptionText(2));
// ...


If that makes things a bit easier for you.

Quote from: Gilbet V7000a on Wed 26/08/2009 04:41:33(I wonder whether the obsoleted 'string' type could ever be used as custom funcion parameters)

As of AGS 2.71 (and regardless of the "Enforce new-style strings" option) you cannot pass a string-literal through a string parameter. If you need something that will allow you to pass a string-literal value you can use either const string or String. const string as the name might imply indicates that the value of the parameter is constant. The function cannot make any changes to the value of the string whatsoever.

Partially the reasoning for this is that old-style strings were passed to functions by reference which means that you could do:

function GetPlayerName(string buffer) {
 StrCopy(buffer, character[GetPlayerCharacter()].name);
}


You could actually modify the value of the string passed to the function. New-style Strings are passed to functions by value. That means that if you do:

function GetPlayerName(String buffer) {
 buffer = player.Name;
}


Only the local copy of the String buffer will be changed; the String you passed as the parameter will not.

So clearly this is a major difference in the way that the two string types work and in order for a string-literal to work with a String parameter CJ had to make them a constant value (although obviously if you passed a string-literal to a string parameter you wouldn't be able to read back the buffer).

In short, if you need a parameter that will work with both old- and new-style strings use const string (which is increasingly uncommon with the limited functionality of old- vs. new-style strings). Otherwise use String.

Just to give things some perspective, none of the modules I've released since AGS 2.71 have used 'const string' for anything (well...with the possible exception of the rare cases that I did some backwards compatible versions, perhaps of StrAdditions or such). Never once has anybody ever complained about me using 'String' instead. ;)

@Gilbot (below): I think your entire post is not helping with this thread! :P I put it here primarily for you. If it's really a problem I can take it out though... ::)
Title: Re: Function in a dialog
Post by: Gilbert on Fri 28/08/2009 15:53:28
I think the second half of your post is not really helping with this thread. :P
Title: Re: Function in a dialog (SOLVED)
Post by: Joseph on Sun 30/08/2009 04:37:55
Well everything works great.

I decided to put everything as a mini tutorial so if ever people use the search function they come across this thread, it will be nice and clear!

To have your own fonts + colors per character, do this:

Step 1
Add this to your GlobalScript.asc:

function SayCustomFont(this Character*, String message)
{
if (this == cEgo)
{
  SetTextWindowGUI (19);
  Game.SpeechFont = eFontEgoSpeech;
}
else if (this == cRoger)
{
  SetTextWindowGUI (16);
  Game.SpeechFont = eFontRogerSpeech;
}  
else
{
  SetTextWindowGUI (7);
  Game.SpeechFont = eFontDefaultSpeech;  
}

The number next to GUI in parathensises is the number of the textGUI you want displayed for that character...when you change its text color in its properties, that changes the color of your character's font. The "eFont_yourfont" part...well, just place  the font's script name you have designated for that particular character's speech font...and voila!

Step2

Place this in your GlobalScript.ash:

import function SayCustomFont(this Character*, String message);

Step3

When you type in dialog text, use this syntax instead of the traditional way (example):

 cEgo.SayCustomFont("Hi, I'm using a custom font.");
 cRoger.SayCustomFont("So am I! My font is different to yours!");

If you want to display your dialog options, use this syntax:

player.SayCustomFont(dDialogname.GetOptionText(1));

...where "player" can be replaced with "cEgo", and the number is the number of the dialog option question...cDialogname is the name of your current dialog.

Now you have it all setup so that each character will have their own color + font (and text border too)!!

Thanks to everyone who contributed...Im sure this will be added in a new version of AGS though...but atleast we gots this now, temporarily :)
Title: Re: Function in a dialog (SOLVED...TUTORIAL INCLUDED)
Post by: Joseph on Fri 04/09/2009 18:02:28
Ok, sorry for re-opening this but I hit this one little snag-a-roonie:

As you know, everything is ay-oh-kay, however, when normal text has to be displayed (like displayAt or something), it will use the last used "SetTextWindowGUI" color...how would one go about making it so that if no character is speaking and the "normal text" to be displayed is always the same SetTextWindowGUI"...

I tried this but it doesnt work:

else
{
   SetTextWindowGUI (7);
   Game.SpeechFont = eFontDefaultSpeech;   
}


Im thinking that "else" will cover everything, as in, if no one is speaking, but its normal text, the SetTextWindowGUI will always be #7.

Title: Re: Function in a dialog (I HIT A SNAG-A-ROONIE)
Post by: Khris on Fri 04/09/2009 18:46:55
Could you show us the complete function body?
Title: Re: Function in a dialog (I HIT A SNAG-A-ROONIE)
Post by: Joseph on Fri 04/09/2009 19:48:23
Hey Khris!

function SayCustomFont(this Character*, String message)
{
if (this == cEgo)
{
   SetTextWindowGUI (19);
   Game.SpeechFont = eFontEgoSpeech;
}
else if (this == cRoger)
{
   SetTextWindowGUI (16);
   Game.SpeechFont = eFontRogerSpeech;

else
{
   SetTextWindowGUI (7);
   Game.SpeechFont = eFontDefaultSpeech;   
}


I think the main problem is where I have "else"....I know I need some sort of :

else if (this=not a character speaking but just a normal text display")
{
   SetTextWindowGUI (7);
   Game.SpeechFont = eFontDefaultSpeech;
}

its the "not a character speaking" script I cant seem to get.
Title: Re: Function in a dialog (I HIT A SNAG-A-ROONIE)
Post by: monkey0506 on Fri 04/09/2009 20:01:02
Under what circumstances would you be calling your extender method, Character.SayCustomFont and not have a Character saying something. Perhaps you could set something up in rep_ex(_always) to restore the defaults for normal Display calls (which I think is what you're wanting to use it for here?).

Then again that might involve checking a lot of different variables to check if a character is speaking and you wouldn't want it to be getting triggered before the character got the chance to start! Maybe the best option then would be just a generic RestoreDefaultFont function (not an extender!) that would set the text window GUI and speech font.

You could call RestoreDefaultFont after using SayCustomFont to ensure that if you used a text window for something other than character speech that it would use the default window instead.
Title: Re: Function in a dialog (I HIT A SNAG-A-ROONIE)
Post by: Khris on Fri 04/09/2009 20:02:54
You could use a dummy character for display calls.
I'd still like to see the complete function body though.
Title: Re: Function in a dialog (SOLVED)
Post by: Joseph on Sat 05/09/2009 01:22:17
Hey!
I used your suggestions...

This is what I did:

Put this in my GlobalScript.ash:

import function ResetTextGUI();


Placed this sucker in my GlobalScript.asc:


function ResetTextGUI()
{
   SetTextWindowGUI (7);
   Game.SpeechFont = eFontNormal;
}


so...after every dialog I just call that to set the text back to default.

Thanks everyone!

:)
Title: Re: Function in a dialog (SOLVED)
Post by: monkey0506 on Sun 06/09/2009 04:20:28
I wasn't entirely certain exactly what you were trying to accomplish here, but glad you got it sorted out.

From what I understand you basically are just implementing a custom method so that each character's speech can appear in a customized way unique to that character (which isn't a bad idea, nice effect). I'd just like to make sure you understand Joseph that the reason you can't just use else clause to reset the default is because you're not going to call the (extender) function without having to use a valid character. Thereby you would never call the code to reset the defaults.

Anyway, it's great you got it working now.
Title: Re: Function in a dialog (SOLVED)
Post by: Joseph on Sun 06/09/2009 13:12:52
Hey Monkey,

Sorry if I wasnt very clear...Ive been watching too many movies of turtles lately and it tends to mess me up quite a bit (see the link) LOL!!

Thanks for you help though, I *think* I understand what you mean with never calling the code.

Title: Re: Function in a dialog (SOLVED)
Post by: AdamM on Mon 07/09/2009 11:47:56
Sorry about the 'string' 'String' confusion; I'm very bad at checking my scripts :D

I'm glad my SayCustomFont function worked for you though.