direct access to actor from a variable

Game Editor comments and discussion.

direct access to actor from a variable

Postby Fojam » Fri Jan 20, 2012 5:12 pm

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?
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score

Re: direct access to actor from a variable

Postby skydereign » Fri Jan 20, 2012 6:15 pm

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: direct access to actor from a variable

Postby Fojam » Fri Jan 20, 2012 6:21 pm

wow thats very confusing but i think i got it. ill get back to you once i try that out
CLICK TO GIVE ME POINTS

My Latest Projects:
Super Smash Bros: viewtopic.php?f=6&t=12307 PLEASE help by making sprites!
User avatar
Fojam
 
Posts: 513
Joined: Thu Mar 19, 2009 10:02 pm
Location: under your bed!!!
Score: 69 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest