probably a simple question

Non-platform specific questions.

probably a simple question

Postby DocRabbit » Fri Oct 27, 2006 1:28 pm

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?
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby makslane » Fri Oct 27, 2006 4:41 pm

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"
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DocRabbit » Sat Oct 28, 2006 12:17 am

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.
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby makslane » Sat Oct 28, 2006 1:04 am

In some event of your text actor, put:

Code: Select all
sprintf(text, "%ld-%ld", otheractor.x, otheractor.y);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DocRabbit » Sat Oct 28, 2006 1:45 am

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.
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby DilloDude » Sat Oct 28, 2006 3:17 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Worked like a charm!

Postby DocRabbit » Sat Oct 28, 2006 5:45 am

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..
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest