Page 1 of 1

storing actors(clones) in an array? how to?

PostPosted: Fri Jun 10, 2011 3:32 pm
by sonicfire
is it possible to store pointers to newly created actors in an array for later usage??

i´m thinking of something like this:
Code: Select all
Actor *newac;
newac = CreateActor("char1", "anim1", "(none)", "(none)", 0, 0, true);
actarray[column][row]=newac; // EDIT: how would i define a global "array of actor" ??


However, how would i then access those actors / clones within script?
Code: Select all
Actor *actchange;
actchange = actarry[column][row];
actchange->animpos = blabla;


Is this somehow possible? What would be the correct way here? I assume i need sprintf somehow, right?
can anybody help or enlighten me? that would be MUCH appreciated. Thanks!!

Re: storing actors(clones) in an array? how to?

PostPosted: Fri Jun 10, 2011 7:24 pm
by skydereign
Well, there are two things you can do. One is to just declare an array of Actor*s, like this.
Code: Select all
Actor* createdActors[10];


That might be what you want, the other is to save the string and int values and use a getclone derivative. To access a value from the above array, do this.
Code: Select all
Actor* control = createdActor[0];
createdActors[2]->x=100;

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 8:12 am
by sonicfire
thanks, sky! :)

but i´m a bit confused here, so i would setup the array like this: (in my case)
Code: Select all
Actor* robots[7][7];


then i would want to store pointers to my actors like so:
Code: Select all
for (b=0; b<7; b++)
    {
        for (c=0; c<7; c++)
        {
            robots[b][c]=CreateActor("robot", "anim", "(none)", "(none)", whateverX, whateverY, true);
        }
    }



and to change anything in any actor (clone) i could simply do this??
Code: Select all
robots[whatever][yup]->myActorVar=100;

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 8:31 am
by skydereign
Yeah, that would work. Though if you were just using clones of the same actor you could use just use a getclone2 derivative.

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 8:11 pm
by NightOfHorror
wait, so is a char an actor in a character like A char would be an A actor. What I am meaning is the character represents an actor, so would a string be A, s, 8, T, 3, or char [6] because sixth would be a null actor.
I am probably wrong, but I want to learn, and by the way what is a null actor?

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 10:38 pm
by skydereign
A null actor and null character are different things. A null actor is a nonexistant actor (will be an actor with cloneindex -1). A null character is represented as this '\0' in code. Characters are single letters, while actors are large objects in gameEditor.

In the gameEditor built in functions, you pass them a string (with the actors name) and it uses it to get the actual actor, and change things. So, characters do not actually represent an actor, but can be used to get them (like in getclone).

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 10:58 pm
by NightOfHorror
So the chars in a string are just ways to get actual actor and change it

Re: storing actors(clones) in an array? how to?

PostPosted: Sat Jun 11, 2011 11:10 pm
by skydereign
Kind of. Think of it this way. Every actor has a name, cloneindex, and a clonename. All of these are ways of accessing the actor. So, when pass a function "actorName", it will search for an actor with the name actorName. If you pass it "enemy.5", it will search for an actor with clonename enemy.5. If it finds it, it will act on it (such as destroy it, or change its animation).

A char itself doesn't do anything to get an actor. A combination of chars (a string) still don't do anything to get an actor. But, gameEditor will check to see if it can find another string to match the string you pass. If it finds one then it will use that actor. But you can't do this since nothing has been done to get an actor.
Code: Select all
"enemy.5".x=0;

So, gameEditor gives us a way of using a string to get an actor. That is why we have the getclone function. It will use a string to get an actor.

Re: storing actors(clones) in an array? how to?

PostPosted: Sun Jun 12, 2011 12:06 am
by NightOfHorror
I am getting it a bit more now. Thanks

Re: storing actors(clones) in an array? how to?

PostPosted: Sun Aug 21, 2011 4:27 pm
by sonicfire
well, weird. i just tried the initial method of storing actors... defined a global array of actor in global code.
then i´ve create an invisible "gamelogic" actor to store the newly created actors in my array:
Code: Select all
robots[0][0]=CreateActor... and so on
robots[0][1]=CreateActor... and so on
robots[0][2]=CreateActor... and so on

(just for testing)

now i have the problem that i cant e.g. change positions using
Code: Select all
robots[a][b]->x+=100;

...my actor simply doesn´t move. i´m running this code from a third button actor.

can anybody help me? :)

Re: storing actors(clones) in an array? how to?

PostPosted: Mon Aug 22, 2011 10:59 am
by skydereign
I see the problem. Weird that I didn't have any problems with that before, but here's the fix... Kind of lame, in fact you might as well store the clonenames of the actors instead, but you have to do this (as per usual it has to do with gE parsing the script).
Code: Select all
Actor* actor = getclone(robots[a][b]->clonename);
robots[a][b]->x+=100;

How gE handles actor variables has many problems. In this case what is happening is that it doesn't know to update the actor variables of the given actor stored in the array. Now I'm just assuming (though there aren't many other options), the getclone call is used by gE to add the given actor to the update list. The code you provided should work for the lowest cloneindex actor, as that one is always by default able to be updated. Anyway, the above example you might note does not actually use the actor Actor* that was declared, that's just to show the point.

Re: storing actors(clones) in an array? how to?

PostPosted: Wed Aug 31, 2011 9:17 am
by sonicfire
skydereign, you´re simply great ;) finally tried it and it works...
thanks so much, point given!

EDIT: oh damn, little drawback... works only for the first clone in the array... [0]
never thought that this would involve so much work and fiddling :D

EDIT #2: ok, now it seems to work with all actors ... weird. but great!