Page 1 of 1

direct access to actor from a variable

PostPosted: Fri Jan 20, 2012 5:12 pm
by Fojam
is there a way to get direct access to an actors variables when the name of the actor is a clone and is stored as a string?

example:

on the clone actor i create a actor variable string called myCloneName when it collides with a an actor named "whatever"
Code: Select all
sprintf(collide.myCloneName, "%s" clonename);


on the global code i create a function to try to get the variable to act as an actor name
Code: Select all
void myFunction()
{
    myCloneName.yvelocity-=5;


obviously the syntax is wrong so im wondering what is the right way to do this?

Re: direct access to actor from a variable

PostPosted: Fri Jan 20, 2012 6:15 pm
by skydereign
You can use the getclone function. getclone takes a string (a clonename) and returns an Actor* to the specified clone. Usually though people use a wrapper to getclone, so you just need to specify a name and a index.
Code: Select all
Actor*
getclone2 (char* cname, int cindex)
{
    char buffer[30];
    sprintf(buffer, "%s.%d", cname, cindex);
    return(getclone(buffer));
}

To use an Actor* you need to use ->, instead of actor.variable.
Code: Select all
Actor* test = getclone2("other_actor", 3);
test->r=0; // changes the other_actor.3's color

Re: direct access to actor from a variable

PostPosted: Fri Jan 20, 2012 6:21 pm
by Fojam
wow thats very confusing but i think i got it. ill get back to you once i try that out