Set actor parameters from char variable

Game Editor comments and discussion.

Set actor parameters from char variable

Postby bleok » Sun Mar 06, 2011 4:18 pm

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)
bleok
 
Posts: 8
Joined: Sun Mar 06, 2011 2:31 pm
Score: 0 Give a positive score

Re: Set actor parameters from char variable

Postby AliceXIII » Sun Mar 06, 2011 4:30 pm

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..
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Set actor parameters from char variable

Postby lcl » Sun Mar 06, 2011 4:43 pm

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.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Set actor parameters from char variable

Postby schnellboot » Sun Mar 06, 2011 5:19 pm

why do you have to use getclone lcl?
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Set actor parameters from char variable

Postby bleok » Sun Mar 06, 2011 5:56 pm

oh thanks lcl.
bleok
 
Posts: 8
Joined: Sun Mar 06, 2011 2:31 pm
Score: 0 Give a positive score

Re: Set actor parameters from char variable

Postby lcl » Sun Mar 06, 2011 7:05 pm

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! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Set actor parameters from char variable

Postby AnarchCassius » Sun Mar 06, 2011 9:10 pm

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.
AnarchCassius
 
Posts: 55
Joined: Sat Jan 29, 2011 1:33 am
Score: 6 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest