Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mr_Threepwood on Sun 16/07/2006 21:21:48

Title: printing mouse coordinates
Post by: Mr_Threepwood on Sun 16/07/2006 21:21:48
This is vexing, I'm running into problems every step of the way on what should be simple things.

I want to display the mouse coordinates so I have tried to put them in a string using:

message=("coordinates %d , %d",mouse.x,mouse.y);

However that gets a parse error saying it doesnt like the %d 's, what am I doing wrong?

EDIT:
Nevermind I found out that String.Format is what you need to use to get this to work.  Seems weird though that the other way doesnt work as well, I mean what would you do if you already had a string and wanted to add numbers into it without getting rid of the information?
Title: Re: printing mouse coordinates
Post by: Ashen on Mon 17/07/2006 01:27:52
You'd need to use a 'buffer' string, and the String.Append function, e.g.:


message = "coordinates";
String Temp = String.Format ("%d , %d",mouse.x,mouse.y);
message = message.Append(Temp);

Title: Re: printing mouse coordinates
Post by: monkey0506 on Mon 17/07/2006 02:27:41
message = String.Format("coordinates %d, %d", mouse.x, mouse.y);

Would work, and so would:

message = "coordinates ";
message = message.Append(String.Format("%d, %d", mouse.x, mouse.y));


And:

message = "coordinates ";
message = String.Format("%s %d, %d", message, mouse.x, mouse.y);


And just to keep your possibilities open:

message = String.Format("%s %d, %d", "coordinates", mouse.x, mouse.y);

[EDIT:]

I didn't read all of the edit, d'oh!

However, the message = String.Format("%s %d, %d", message, mouse.x, mouse.y); line would still work. For the exact same results as Ashen's code. ;)