Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: CaptainD on Tue 19/06/2018 22:12:32

Title: DisplayAtY question
Post by: CaptainD on Tue 19/06/2018 22:12:32
Is it not possible to put a variable into a DisplayAtY expression?

Code (ags) Select
DisplayAtY(200, "Cats are on the prowl... they manage to kill %d of your rats", num) returns the error wrong number of parameters in call to 'DisplayAtY' - it works fine with Display but I want to position the text displayed.  Am I missing something obvious or is it simply a limitation of this particular function?  I can't find anything explicit in the manual about this.
Title: Re: DisplayAtY question
Post by: Crimson Wizard on Tue 19/06/2018 22:18:40
Only functions that have "..." in the parameter list may take extra variables to format a string. This is called "variadic function".

Compare:
Code (ags) Select

Display (string message, ...)
DisplayAt(int x, int y, int width, string message, ...)

But
Code (ags) Select

DisplayAtY(int y, string message)



When you need to pass a string somewhere that does not have "...", use String.Format to create a string:
Code (ags) Select

DisplayAtY(200, String.Format("Cats are on the prowl... they manage to kill %d of your rats", num));
Title: Re: DisplayAtY question
Post by: CaptainD on Tue 19/06/2018 22:20:20
Brilliant, thanks so much CW!!