Function in a dialog (SOLVED)

Started by Joseph, Mon 24/08/2009 22:55:24

Previous topic - Next topic

Joseph

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
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Khris

You need to call your functions with () at the end:

Code: ags
 changeSpeechFont();


What error messages did you get?
Did you define eFontDialogOptions yourself?
What happens if you try
Code: ags
Game.SpeechFont = eFontFont1;

?

Joseph

#2
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?
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Joseph

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?
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

AdamM

#4
How does the idea of a custom Say function strike you? (Bear with me here as I've never used extender functions before)

Code: ags

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:

Code: ags
@1
 cEgo.SayCustomFont("Hi, I'm using a custom font.")
 cRoger.SayCustomFont("So am I! My font is different to yours!")
return

Joseph

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!
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

skuttleman

I think you need this line in GlobalScript.ash

Code: ags

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


That should make the function accessible to the dialog scripts.

Joseph

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.
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Gilbert

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:
Code: ags

function SayCustomFont(this Character*, String message)
{


And in the header:
Code: ags

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

Joseph

#9
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---->




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?)


Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Joseph

Oh, and I love turtles.

OKTHANKSBYE
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Khris

Uncheck Say and copy the option text to the dialog script.

Joseph

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 :)
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

monkey0506

#13
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:

Code: ags
@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:

Code: ags
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:

Code: ags
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... ::)

Gilbert

I think the second half of your post is not really helping with this thread. :P

Joseph

#15
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 :)
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Joseph

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:

Code: ags
 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.

Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

Khris

Could you show us the complete function body?

Joseph

Hey Khris!

Code: ags
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.
Spread the love...One.Turtle.At.A.Time.
http://www.youtube.com/watch?v=y0A77rohcyg

monkey0506

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.

SMF spam blocked by CleanTalk