using DisplayAtY with strings

Started by thecatamites, Thu 25/03/2010 23:04:37

Previous topic - Next topic

thecatamites

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:

Code: ags
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.
Games 4 Schools Dot Com play games made for schools and teens to lkearn

Calin Leafshade

dont you need to use String.Format?

so it would be like

Code: ags

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

thecatamites

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
Games 4 Schools Dot Com play games made for schools and teens to lkearn

Gilbert

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

monkey0506

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.

SMF spam blocked by CleanTalk