Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Mon 15/06/2009 21:05:03

Title: SayBackground integer dilema
Post by: geork on Mon 15/06/2009 21:05:03
 Hey all!
  I've been trying to execute this code:
   
    cChar1.SayBackground("try %d", tries);
   

   yet the engine will not allow it, something along the lines of:
     wrong number of parameters in call to 'Character::SayBackground'
   Is there a way of displaying an integer in a say background text?
       Thanks
Title: Re: SayBackground integer dilema
Post by: Trent R on Mon 15/06/2009 21:09:44
You can only do that when the parameter is a const string like in .Say, so for SayBackground use

    cChar1.SayBackground(String.Format("try %d", tries));

Slightly confusing, but easy to solve.


[Edit]: So I might be wrong about the const string thing... but I  know it's related. Either way, String.Format will solve your problem.


~Trent
Title: Re: SayBackground integer dilema
Post by: geork on Mon 15/06/2009 21:30:35
Thanks!
Title: Re: SayBackground integer dilema
Post by: monkey0506 on Tue 16/06/2009 06:32:37
As far as the "const string" dilemma Trent was having, let me spin ye a yarn...

Once upon a time there was a man. A man by the name of Jones. Davy Jones. Christopher Quentin (http://www.americangirlscouts.org/agswiki/Quentin) Quentulus Quazgar (http://en.wikipedia.org/wiki/Places_in_The_Hitchhiker%27s_Guide_to_the_Galaxy#Preliumtarn) Davy (http://en.wikipedia.org/wiki/Davy_Jones%27_Locker) Jones. One day "CJ" as we shall call him, had eaten far more onion rings (http://www.americangirlscouts.org/agswiki/Onion_ring) than any sane man had ever previously in all of mankind's history (or onion ringkind's history either for that matter!) taken upon himself to eat. Thusly was the mystic power of the onion ring revealed unto CJ.

"They came to me in a vision..." he later said, "...the onion rings. They told me...build it...and trolls will come." Shortly thereafter, CJ founded the American Girl Scouts (http://www.americangirlscouts.org/).

It took a while, but trolls came indeed. Ranging as far and wide as TerribleVenerealDiseases all the way to Yoda...man.

They told long, horrible stories that ran rampantly off topic. As AGS grew in strength and members, it wasn't long until they had devised their own demonic language (http://en.wikipedia.org/wiki/Scripting_language). Among this language there were specific words...these words...these...key words to their language...were the basis...the very foundation from which their Girl Scout cookies (http://www.adventuregamestudio.co.uk/games.php) were produced. With these "cookies," the Girl Scouts began to slowly enslave the human race.

And of all the keywords used to produce these cookies, one stood as the most powerful. It had the most opportunity. The most potential for growth and change...evolution if you will. The name of this keyword was....

[*insert dramatic drum roll (http://www.youtube.com/watch?v=oHg5SJYRHA0) here*]

string!

Okay, enough of that tomfooleryishnishness...I was planning more but I'm starting to lose interest and the way I'm leaned over my arm is falling asleep.

"const string" was introduced with AGS 2.71 at the same time as the new String type. The only practical function is if you want/need a function parameter that can accept a string, String, or a string-literal (http://en.wikipedia.org/wiki/String_literal).

In other words, it does the exact same thing as using a String parameter, only with old-style string support. Note that as of AGS 2.71 if you try to pass a string-literal through a string parameter you will get a compile-time error as well.
Title: Re: SayBackground integer dilema
Post by: GuyAwesome on Tue 16/06/2009 10:53:47
Uncle Monkey's Story Timeâ,,¢ aside, I don't know why some functions accept the extra parameters and some don't (and I think it was so before the String/string crossover, so it's not wholly a legacy thing) but a rule of thumb I've spotted: If the manual entry has ", ..." in the sample declaration, like
Display
Display (string message, ...)

Then it can accept the 'optional' parameters for String formatting (e.g. Display, DisplayAt, Character.Think). If it doesn't have the ellipsis (e.g. Character.Say, Character.SayAt, Character.SayBackground, DisplayAtY), you need to use String.Format