Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: thecatamites on Thu 25/03/2010 23:04:37

Title: using DisplayAtY with strings
Post by: thecatamites on Thu 25/03/2010 23:04:37
Hey, I'm trying to use a DisplayAtY function that also displays a text spring. Unfortunately putting in the string name at the end of the text gives me a "wrong number of parameters" error. Here's what the line looks like:

DisplayAtY(180, "Thank you. You have created one Mr. %s , thirty five years old, currently residing in Frog City, USA.", myName);

Are there any workarounds for this problem? Anything I'm doing wrong? Thanks for the help!

EDIT: oh yeah, and myName is a global string variable, so it's not because I didn't define it in the room script.
Title: Re: using DisplayAtY with strings
Post by: Calin Leafshade on Thu 25/03/2010 23:20:36
dont you need to use String.Format?

so it would be like


DisplayAtY(180, String.Format("Thank you. You have created one Mr. %s , thirty five years old, currently residing in Frog City, USA.", myName));
Title: Re: using DisplayAtY with strings
Post by: thecatamites on Thu 25/03/2010 23:46:31
Works perfectly, thank you! I'm fairly new to strings right now so I'm not too familiar with any of the functions  ;D ;D
Title: Re: using DisplayAtY with strings
Post by: Gilbert on Fri 26/03/2010 01:00:04
I think it's a bit odd and inconsistent that Display() and DisplayAt() both support on-the-fly string formatting, whereas DisplayAtY() does not.

Anyway, when in doubt, check the manual on what a specific function can do (though in this case I'll say it's understandable to have overlooked this problem, as it doesn't seem logical for this function not to support string formatting).
Title: Re: using DisplayAtY with strings
Post by: monkey0506 on Fri 26/03/2010 01:32:07
Just as a quick point of reference, any functions which list ... as the final parameter allow string formatting. Those that do not, don't. (And no, you can't create custom functions that support it)

It is inconsistent for this particular function though.