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

Non-platform specific questions.

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

Postby sonicfire » Fri Jun 10, 2011 3:32 pm

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!!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

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

Postby skydereign » Fri Jun 10, 2011 7:24 pm

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

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

Postby sonicfire » Sat Jun 11, 2011 8:12 am

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;
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

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

Postby skydereign » Sat Jun 11, 2011 8:31 am

Yeah, that would work. Though if you were just using clones of the same actor you could use just use a getclone2 derivative.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby NightOfHorror » Sat Jun 11, 2011 8:11 pm

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?
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

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

Postby skydereign » Sat Jun 11, 2011 10:38 pm

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

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

Postby NightOfHorror » Sat Jun 11, 2011 10:58 pm

So the chars in a string are just ways to get actual actor and change it
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

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

Postby skydereign » Sat Jun 11, 2011 11:10 pm

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

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

Postby NightOfHorror » Sun Jun 12, 2011 12:06 am

I am getting it a bit more now. Thanks
viewtopic.php?f=2&t=12136
"I have not failed. I just found 10,000 ways that wont work." quoted by Thomas Edison.
Over the year, I decided my motto for me is I am knowledgeable, but not practical.
User avatar
NightOfHorror
 
Posts: 1823
Joined: Fri Aug 27, 2010 2:50 am
Location: Cedar Hill, MO, of the USA
Score: 51 Give a positive score

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

Postby sonicfire » Sun Aug 21, 2011 4:27 pm

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? :)
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score

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

Postby skydereign » Mon Aug 22, 2011 10:59 am

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

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

Postby sonicfire » Wed Aug 31, 2011 9:17 am

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!
sonicfire
 
Posts: 425
Joined: Wed Nov 01, 2006 9:34 pm
Location: berlin germany
Score: 16 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest