Setting text property from global code

Non-platform specific questions.

Setting text property from global code

Postby morcior » Mon Jan 15, 2007 4:39 am

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.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Novice » Mon Jan 15, 2007 11:23 am

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();
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby morcior » Tue Jan 16, 2007 1:03 am

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?
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby morcior » Tue Jan 16, 2007 1:05 am

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.
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby morcior » Tue Jan 16, 2007 4:40 am

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);

morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby makslane » Tue Jan 16, 2007 5:07 am

You just need a reference in the caller action.
If you put:

Code: Select all
//text_actor
makeText();


will works too!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby morcior » Tue Jan 16, 2007 5:33 am

oh right... that is also weird!

I've never heard of a code parser that reads comments before!
morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest