Page 1 of 1

probably a simple question

PostPosted: Fri Oct 27, 2006 1:28 pm
by DocRabbit
I was wanting to place text in an actor using script editor, and using the x and y coordinates of another actor as the source for this, along with a divider like "-" to separate them. Is there an easy way to do this using scripting?

PostPosted: Fri Oct 27, 2006 4:41 pm
by makslane
To position, just change the x,y coordinates, like in any other actor.
What's the format are you want? Some thing like this?

"100 - 20"

PostPosted: Sat Oct 28, 2006 12:17 am
by DocRabbit
yes, that is how I want to display it on the screen. But it will be the coordinates of a different actor.

Actor1(animated bmp)(x,y)

Actor2(Text Readout)

Trying to figure out how to get x,y (Integers) and "-"(String) combined into a String to display for Actor2.text=

BTW, I love this program already, just hope to get more proficient with it. I am more Graphics oriented, my programming is rusty, but I am "tickled to death" with the easy of high-quality graphic animations it handles with ease.

PostPosted: Sat Oct 28, 2006 1:04 am
by makslane
In some event of your text actor, put:

Code: Select all
sprintf(text, "%ld-%ld", otheractor.x, otheractor.y);

PostPosted: Sat Oct 28, 2006 1:45 am
by DocRabbit
When I tried it I get a runtime error sprintf creating an empty string about half the time when I try it, the other half, I get "0-0" displayed for the text actor.


I had been trying something similar:

Code: Select all
sprintf(Actor2.text,"%d-%d", Actor1.x, Actor1.y);


I am using mouse button dwn(Left Btn) event on Actor2 with script editor action.

PostPosted: Sat Oct 28, 2006 3:17 am
by DilloDude
Because %d makes it an integer, and x and y are reals, you need to cast them to an int:
Code: Select all
sprintf(Actor2.text, "%d-%d", (int)Actor1.x, (int)Actor1.y);
Alternatively, you can use %f to make a real, but you probably won't need that.

Worked like a charm!

PostPosted: Sat Oct 28, 2006 5:45 am
by DocRabbit
Thanks a million Dillo, it worked perfectly. Guess I should drag those programming books out of the closet.... :) This has got to be the best board I have ever been on, everyone here helps without question. I am a lifer for GE now..