Page 1 of 1

Setting text property from global code

PostPosted: Mon Jan 15, 2007 4:39 am
by morcior
Can you set a text actors properties from global code?

if you make a function like:

Code: Select all
void makeText()
{
    sprintf(text_actor.text, "hello world");
}


The actor's text does not change when you call this function. I have also noticed I can't change text actors x,y coordinates from global code, but actors with animations work fine.

PostPosted: Mon Jan 15, 2007 11:23 am
by Novice
I think you have to add a reference of the actor from wherever you are calling the function, like this
Code: Select all
//text_actor
makeText();

PostPosted: Tue Jan 16, 2007 1:03 am
by morcior
How do you mean?

You can write code like this:

Code: Select all
Global code:

void makeText(Actor *act)
{
  sprintf(act->text, "hello world");
}

Other code:

makeText(&text_actor);



but this kind of defeats the point, and begs the question why can you reference normal actors without a pointer, but not text actors?

PostPosted: Tue Jan 16, 2007 1:05 am
by morcior
Just to make myself clear:

Code: Select all
GLOBAL CODE:

void moveActor()
{
   an_actor.x += 10;
}


If you run this code on an actor with an animation it will move the actor.

If you run this code with a text actor, no errors are returned and the text actor does not move.

PostPosted: Tue Jan 16, 2007 4:40 am
by morcior
after more investigation I noticed you can pass a reference to the text actor to a globally defined function, even if there is no parameter defined in the global function!! I guess this fixes the problem I was having but it seems very peculiar behaviour.. perhaps a bug?

global code
Code: Select all

void makeText()
{
    sprintf(text_actor.text, "hello world")
}



actor mouse button down event:
Code: Select all

makeText(&text_actor);


PostPosted: Tue Jan 16, 2007 5:07 am
by makslane
You just need a reference in the caller action.
If you put:

Code: Select all
//text_actor
makeText();


will works too!

PostPosted: Tue Jan 16, 2007 5:33 am
by morcior
oh right... that is also weird!

I've never heard of a code parser that reads comments before!