Page 1 of 1

Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 4:18 pm
by bleok
Hi.
I'm trying to write some functions universal for several actors, but i don't know how to change actors parameters, using a char variable with actors name. For example:
Code: Select all
void ChangeAngle(char actorname[32], int newangle) {
if (...something...){
actorname.angle = newangle;
}
}


This doesn't work. I've tried to use brackets in actorname.angle, but had no result.
It"ll be nice if someone could help me.

P.S. Sorry if its something wrong with my english)

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 4:30 pm
by AliceXIII
Code: Select all
void ChangeAngle(char *actorname[32], int newangle) {
if (...something...){
actorname.angle = newangle;
}
}


When using char you need to use it like so

char *actorname[32]

putting the asterisk before the character variable..

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 4:43 pm
by lcl
AliceXIII wrote:
When using char you need to use it like so

char *actorname[32]

putting the asterisk before the character variable..

No you don't. char actorname[32] will be string with length of 32 chars.

@ bleok:
Code: Select all
void ChangeAngle(char actorname[32], int newAngle)
{
    Actor * a = getclone(actorname);
    a->angle = newAngle;
}

This works. :)
Just remember to give value to directional_velocity also or your actor won't move.

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 5:19 pm
by schnellboot
why do you have to use getclone lcl?

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 5:56 pm
by bleok
oh thanks lcl.

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 7:05 pm
by lcl
schnellboot wrote:why do you have to use getclone lcl?

It doesn't work without. Without getclone() it is just string. With getclone() it can be transfered to actor. :)

@bleok: you're welcome! :)

Re: Set actor parameters from char variable

PostPosted: Sun Mar 06, 2011 9:10 pm
by AnarchCassius
You can use a pointer instead:

Code: Select all
void ChangeAngle(Actor *this, int newAngle)
{
    this->angle = newAngle;
}


but then you a pointer for the arguments so you're probably using getclone on the other end. This way is useful if your already working with a pointer in the context the function is called though.