printing mouse coordinates

Started by Mr_Threepwood, Sun 16/07/2006 21:21:48

Previous topic - Next topic

Mr_Threepwood

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?
I am a mighty pirate

Ashen

You'd need to use a 'buffer' string, and the String.Append function, e.g.:

Code: ags

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

I know what you're thinking ... Don't think that.

monkey0506

#2
Code: ags
message = String.Format("coordinates %d, %d", mouse.x, mouse.y);


Would work, and so would:

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


And:

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


And just to keep your possibilities open:

Code: ags
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. ;)

SMF spam blocked by CleanTalk