Actor Pointer Discussion

You must understand the Game Editor concepts, before post here.

Actor Pointer Discussion

Postby EvanBlack » Fri Oct 07, 2011 2:01 am

Ok. So I am playing with Actor Pointers and trying to figure out there use, where they are stored, and how to use them properly. Currently I have a few tabs open about Actor Pointers I searched for. I just want to get some for sure answers about which pointers do what, and what they are ACTUALLY pointing to.


So the Actor* returned by CreateActor() is just a temporary pointer and can be used to access the newly created actors variables? This is how it seems to me when I try to use it to store the actor in an Actor*.

So how do these functions work?

GetActor()

GetClone()


What kind of pointer do they return? Is it the pointer to the actual actor, or just a temporary placeholder pointer to access the actor?

Could I then store the address of the actor using the get function for later access to the actor?

It seems that the easier method of accessing actors is using their names, or x,y positions. This way you can, as skydereign as mentioned in another post, get the needed actor.

So to store the actor clone name...

Could you do this?

cloneNameArray[x] = CreateActor()->clonename;

Then later when you want to change something in that actor..

Could you do something like this?

getclone(cloneNameArray[x])->variable = value;




How about if I don't know the clone name of an actor but I have the x,y position I want to check... could I do?

type variable = getactor(x,y)->variable

or even change a variable

getactor(x,y)->variable = variable2



or could I just store the actor pointers retrieved for later use?

Such as:

Actor* myActorPtr = getactor(x,y)

or

Actor* myActorPtr = getclone(clonename
)



Then use those pointers to access the Actor directly through:

myActorPtr->variable

or even create new pointers or possibly double pointers

Actor* myActorPtr2 = *myActorPtr

Actor** myActorPtr3 = &myActorPtr





So how do these mysterious Actor Pointers really work?
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Actor Pointer Discussion

Postby skydereign » Fri Oct 07, 2011 5:43 am

Okay, first thing to know, Actors are a type of struct. You come from C++ so you should understand structs/classes, so I won't go into that. But, they exist in your game, and hold the actor's variables. The actual game engine will go through them and update the view accordingly.

But, these structs are not temporary. They are created and stored in memory when ever an actor is created, and are removed when an actor is destroyed. As you have noted, CreateActor, getactor, and getclone, all return an Actor*. This is just a pointer to the actor struct (a pointer to Actor). If you don't store it, by setting an Actor* equal to it, then it in a way disappears. But, since CreateActor returns an Actor*, you can also do this.
Code: Select all
CreateActor("actor", "anim", "(none)", "(none)", 0, 0, true)->r=0;

This uses the Actor* and sets the newly created actor's r to 0. You could accomplish the same thing like this.
Code: Select all
Actor* save = CreateActor("actor", "anim", "(none)", "(none)", 0, 0, true);
save->r=0;
save->g=0;
save->b=0;

If you ignore the last two lines, the code does the same thing. Of course if you include the last two lines, you can see that you can set several variables, instead of only being able to set one.

So, the actor is created, and CreateActor returns the pointer to the newly created actor. But, that does not mean it is temporary. It is the same thing as declaring any other variable. If you store the pointer using an Actor*, then the Actor* will continue to exist until the Actor* leaves scope. This is the same as a function returning an integer. You can use it, store it, but eventually it disappears.

And your understanding of getclone and getactor seems sufficient. You can use them on call, or store the Actor*s as needed. As long as you declare the Actor* in global scope, the Actor * can be used whenever you want.

One thing though is that all three of those functions can return an invalid actor (as described in the Script Reference).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron