Page 1 of 1

Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 11:25 am
by Zehper48
Hello GE,
How can I make a canvas draw all instances of a cloned actor, at the moment it is only drawing the first one and non of the others.
Thank you

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 11:42 am
by lcl
Use this kind of code:

Code: Select all
int i;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("clones"); i ++) //Check all clones through.
{
    sprintf(actor, "clones.%i", i); //Set the name of actor to draw.
    draw_from(actor, 0, 0, 1); //Draw it.
}


Change "clones" to the name of your cloned character.
:D

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 12:23 pm
by Zehper48
Thanks alot for helping :)

Code: Select all
int i;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    sprintf(actor, "smile.%i", i); //Set the name of actor to draw.
    draw_from(actor,200+actor.x-Player1.x, 200+actor.y-Player1.y, 1); //Draw it.
}

Here is what i have now, but i have an Illegal structure on line 6,
The code for line 6 is to draw all clones of "smile" according to where they are in relation to Player1.
What am I doing wrong?

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 12:34 pm
by skydereign
Yeah, to do what you want to do, you'll need to use an Actor *. Would look like this.
Code: Select all
int i;
char buffer[50]; //String for actors name.
Actor* actor;

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    sprintf(buffer, "smile.%i", i); //Set the name of actor to draw.
    actor=getclone(buffer);

    if(actor!=NULL)
    {
        draw_from(actor->clonename,200+actor->x-Player1.x, 200+actor->y-Player1.y, 1); //Draw it.
    }
}

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 12:43 pm
by lcl
actor is now just string, not Actor.
That's why you can't get its coordinates.

Do this:

Global code:
Code: Select all
char actorName[50];

Actor * GetClone(char Name[50], int num)
{
    sprintf(actorName, "%s.%i", Name, num);
    return getclone(actor);
}

Then give name to it and click add.

And now your script:
Code: Select all
int i;
Actor * this;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    this = GetClone("smile", i);
    sprintf(actor, "smile.%i", i); //Set the name of actor to draw.
    draw_from(actor,200+this->x-Player1.x, 200+this->y-Player1.y, 1); //Draw it.
}

Now it works because now you deal those positions with actor itself, not its name. :)

EDIT:
Seems you just were faster again, skydereign...

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 1:17 pm
by Zehper48
skydereign, I tried using your code, Thanks so much for helping me out, I didn't get any errors, but my clones didnt appear in the canvas

Lcl,
when i enterd the method into the global code it said
undeclared identifier actor line 5

I attached my game, if you could take a look at it, i would greatly appriciate

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 1:24 pm
by skydereign
Umm, weird. They did for me. Here is your ged with the code inserted.

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 1:27 pm
by lcl
Zehper48 wrote:skydereign, I tried using your code, Thanks so much for helping me out, I didn't get any errors, but my clones didnt appear in the canvas

Lcl,
when i enterd the method into the global code it said
undeclared identifier actor line 5

I attached my game, if you could take a look at it, i would greatly appriciate

Yeah, sorry. That global code thing last line.. change actor to actorName :)

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 1:28 pm
by Zehper48
It was the order i had the code inserted! Haha didn't think It would make a difference for that instance, but it works now!
Thank you so much! =]

Re: Making a canvas draw all instances of a clone?

PostPosted: Sun Mar 06, 2011 1:31 pm
by Zehper48
Thank you both,
Both the codes work perfect!