SayBackground integer dilema

Started by geork, Mon 15/06/2009 21:05:03

Previous topic - Next topic

geork

 Hey all!
  I've been trying to execute this code:
   
Code: ags

    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

Trent R

#1
You can only do that when the parameter is a const string like in .Say, so for SayBackground use
Code: ags

    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
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

geork


monkey0506

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 Quentulus Quazgar Davy Jones. One day "CJ" as we shall call him, had eaten far more onion rings 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.

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. 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 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 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.

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.

GuyAwesome

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

SMF spam blocked by CleanTalk