Page 1 of 1

sprintf(text, "%d", x) always gives 0

PostPosted: Wed Mar 17, 2010 9:57 am
by akr
Hi,

Why do I always get 0 in text? What is the best way to compare the x and y coordinate of an actor with screen boundaries?

Andreas

Re: sprintf(text, "%d", x) always gives 0

PostPosted: Wed Mar 17, 2010 12:20 pm
by makslane
x is an float variable.
So, use:

Code: Select all
sprintf(text, "%f", x);


Or:

Code: Select all
textNumber = x;


What is the best way to compare the x and y coordinate of an actor with screen boundaries?


You can compare the xscreen and yscreen of the actor with the width and height of the view.

Re: sprintf(text, "%d", x) always gives 0

PostPosted: Wed Mar 17, 2010 4:50 pm
by Bee-Ant
akr wrote:Hi,

Why do I always get 0 in text? What is the best way to compare the x and y coordinate of an actor with screen boundaries?

Andreas

Hmm...did you want to check some actor x and y coordinate by displaying their values on screen?
Code: Select all
int i=actor.x;
int j=actor.y;
sprintf(text,"%i,%i",i,j);

You can't just add them directly.

Re: sprintf(text, "%d", x) always gives 0

PostPosted: Thu Mar 18, 2010 8:39 am
by akr
%i will not work. It is a float. Will use %f like maks mentioned.

Whats the reason for x to be float? As far as i know xmouse is integer. I am confused. Is there a document where I can find the types?

Andreas

Re: sprintf(text, "%d", x) always gives 0

PostPosted: Thu Mar 18, 2010 1:36 pm
by makslane
Whats the reason for x to be float? As far as i know xmouse is integer.


In the fisrt GAme Editor versions the x and y was integer.
But some games need screpts like " x += 0.5;". So x and y are promoted to double vars.
The xmouse and ymouse keep integer (the mouse always returns integer coordinates).

I am confused. Is there a document where I can find the types?


Only in the code:
http://code.game-editor.com/browser/tru ... ne/Actor.h (struct stActorVars)
http://code.game-editor.com/browser/tru ... e/Script.h

Script reference:
http://game-editor.com/docs/script_reference.htm