help with clone actors

Non-platform specific questions.

help with clone actors

Postby mrgame » Mon Feb 11, 2008 6:40 pm

how would i make this work even if i cloned the actor. so only 1 would follow not all of them

if (player.x <terrorist.x + 200)
if (player.x >terrorist.x - 200)
if (player.y <terrorist.y + 200)
if (player.y >terrorist.y - 200)

{
MoveTo("Event Actor", 0.000000, 0.000000, 3.000000, "player", "map");
}



change terrorist so if there was 10 terrorists and i was close 2 one of them only 1 would follow

eg if (player.x <event actor + 200) but that dosnt work
mrgame
 
Posts: 118
Joined: Sun Oct 21, 2007 8:09 pm
Location: my computer
Score: 3 Give a positive score

Re: help with clone actors

Postby edh » Mon Feb 11, 2008 8:08 pm

You could loop through the terrorists with something like

Code: Select all
    Actor *actor;
    int i;
    int count = ActorCount("terrorist"); // "terrorist" would be replaced with actual actor name
    for(i = 0; i < count; i++)
    {
       sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
       actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
       if (player.x < actor->x + 200
            && player.x > actor->x - 200
            && player.y < actor->x + 200
            && player.y > actor->x - 200)
       {
           // do something awesome
       }
    }



Note: I'm not near my GE right now so that code is only a sketch
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: help with clone actors

Postby DilloDude » Mon Feb 11, 2008 8:22 pm

If the event is on the actor you want to check (in this case the terrorist), you can just use this:
Code: Select all
if (player.x < x  + 200)
Code: Select all
    Actor *actor;
    int i;
    int count = ActorCount("terrorist"); // "terrorist" would be replaced with actual actor name
    for(i = 0; i < count; i++)
    {
       sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
       actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
       if (player.x < actor->x + 200
            && player.x > actor->x - 200
            && player.y < actor->x + 200
            && player.y > actor->x - 200)
       {
           // do something awesome
       }
    }


Looping through all clones this way can work, but it gets messed up if the actors are destroyed. I prefer to maintain an array, and loop through that.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: help with clone actors

Postby edh » Mon Feb 11, 2008 8:37 pm

I was thinking about it a little more, I think your question was about how to get 1 guy to follow (probably the closest guy).

In that case, you will want a function to calc min distance. Then iterate over each clone and find the one closest. Once you've found the closest, make him move.

your dist function could be something like
Code: Select all
int calc_dist(Actor * obj1, Actor * obj2)
{
   // pythagorean theorem here c = sqrt(a*a + b*b), maybe should return a double
}


then you would find the closest guy and do something with him

Code: Select all
Actor *closest;
int minDist = 0;
int newDist;

for(i = 0; i < count; i++)
{
    sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName
    actor = getclone(cloneName); // get a pointer to a clone called "terrorist.1" for example
    theDist = calc_dist(player, actor);
    if (theDist < minDist || minDist == 0)
    {
        minDist = theDist;
        closest = actor;
    }
}


// move closest actor or do whatever
User avatar
edh
 
Posts: 233
Joined: Thu Sep 13, 2007 12:17 am
Location: Maine, USA
Score: 14 Give a positive score

Re: help with clone actors

Postby equinox » Fri Feb 15, 2008 10:21 pm

Hi at all,

Please: What must she make sprintf(cloneName, "%s.%d", "terrorist", i); // need to malloc a character buffer called cloneName

and as I use it?

Tnk1000 for reply.

P.S.:I have read and reread the script refence doc, but I find it hard to understand the operation of GE, in more' I must translate from the English in Italian...
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: help with clone actors

Postby DilloDude » Sat Feb 16, 2008 12:21 am

sprintf writes a formatted string into another string. The first string (cloneName in this example) is the destination. Next is the format string, in this case "%s.%d". %s means print a string. %d (or %i) means print an integer. (for a full list of format types and things, go to http://www.acm.uiuc.edu/webmonkeys/book ... tml#printf ). Next are the variables to fill. First, in this case, is "terrorist", which is the string to put where th "%s" is in the format string. Then, is an int, i, used to replace the "%d". So, the final result depends on i. If i = 3, then cloneName will be set to "terrorist.3".
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: help with clone actors

Postby Bee-Ant » Sat Feb 16, 2008 1:53 am

mrgame wrote:how would i make this work even if i cloned the actor. so only 1 would follow not all of them

if (player.x <terrorist.x + 200)
if (player.x >terrorist.x - 200)
if (player.y <terrorist.y + 200)
if (player.y >terrorist.y - 200)

{
MoveTo("Event Actor", 0.000000, 0.000000, 3.000000, "player", "map");
}



change terrorist so if there was 10 terrorists and i was close 2 one of them only 1 would follow

eg if (player.x <event actor + 200) but that dosnt work

Code: Select all
if(terorist.x<player.x+200&&terorist.x>player.x+5)
{
    terorist.x-=3;
    ChangeAnimation("terorist","walkleft",FORWARD);
}
if(terorist.x>player.x-200&&terorist.x<player.x-5)
{
    terorist.x+=3;
    ChangeAnimation("terorist","walkright",FORWARD);
}
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: help with clone actors

Postby equinox » Sat Feb 16, 2008 7:12 am

Thanks1000 for the explanation,DilloDude. Perhaps you can still help me,please,, with "Clone INDEX":

In game maker I use,for istance:

ID = CreateActor (Hand, x, y);<---returb id'obj(or Actor in GE)

ID = 123450 <--id of object Hand...then I can do:

1 #ID.x = 10;..ID.FLAG = true..or
2 #(123450).x = 10.... is it used so', perhaps,CLONE INDEX?
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: help with clone actors

Postby Bee-Ant » Sat Feb 16, 2008 7:52 am

What's clone Index used for anyway? :roll:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: help with clone actors

Postby DilloDude » Sat Feb 16, 2008 9:24 am

cloneindex is the number of the clone. It is a read-only actor variable. If you want to store a reference to an actor, use either a string or an Actor *(pointer to an actor). The CreateActor function returns an Actor *, so you can use this information for either:
Code: Select all
Actor *a = CreateActor(...
strcpy(string_value, a->clonename);
a->x = 10;

Then, if you want to get the actor using the string:
Code: Select all
Actor *a = getclone(string_value);
a->yvelocity = 18;
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: help with clone actors

Postby Bee-Ant » Sat Feb 16, 2008 9:28 am

.... :roll: :roll: :roll:
Btw, when your Super-Human will come???
I never seen your game before
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: help with clone actors

Postby equinox » Sat Feb 16, 2008 11:15 am

Hi Dude,
I have tried your code it is it works well, Tnk1000.

Actor* ACT, *ACT1;
ACT = getclone(ENEMY); <-----------------------------------global.code: #define ENEMY "enemy_1"
strcpy(NOME, ACT->clonename);
ACT1 = getclone(NOME);
ACT1->xvelocity = 2;
> work......

but if I write this code:... Where am I wrong?

//ACT1->xvelocity = 2;
DestroyActor("ACT1"); or DestroyActor(ACT1);....no.
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: help with clone actors

Postby DilloDude » Sat Feb 16, 2008 11:22 am

DestroyActor uses a string, so you'd use:
Code: Select all
DestroyActor(ACT1->clonename);
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: help with clone actors

Postby equinox » Sat Feb 16, 2008 3:11 pm

Yes,Dillo, works, thanks. I have tried:
DestroyActor (Name) == DestroyActor (ACT1 - > CLONENAME) / / Work
========================================
Now another question. This is VERYdifficult, at least for me.

I create a #1 Hero, I create #3 ENEMY. Hero against 3 ENEMY.

The hero shoots a bomb against one any of the 3 enemies. When the bomb collides with one of them, the bomb as it does to find the id of the enemy and therefore to destroy it or to get away HP?

I am reading getAllActorrsInCollision (...),,,but I don't succeed in finding the solution.
----------------------------------
My idea is: create an array of all the enemies and choose one of them, finding his x, y,, to be been able to launch the bomb to those coordinates of enemy.x/enemy.y. Can yuo,please, help me?

==============================================
Reading among the various posts, I have found this --> http://game-editor.com/forum/viewtopic. ... =getclone2
but I don't understand it. : ship.x = getclone2("transporterEnd", collide.cloneindex)->x;

but I believe that it am very useful...I believe...the part collides.cloneindex that seems useful.
=========================================
I am trying the function to collide, but something doesn't go. Are you able, please, can you look the code? PACMAN eats the yellow dots but also the blue sprite......and this must not happen, now.
Attachments
MIO.rar
(146.61 KiB) Downloaded 154 times
User avatar
equinox
 
Posts: 118
Joined: Tue Jan 29, 2008 3:38 pm
Score: 0 Give a positive score

Re: help with clone actors

Postby DilloDude » Fri Feb 22, 2008 2:04 am

In pacman->drawActor, check name, rather than clonename, and it should be 0. strcmp returns 1 if the strings are different:
Code: Select all
if(strcmp(actors[i].name, "PUNTO") == 0)

In a collision event, use 'collide' to access the collide actor:
Code: Select all
collide.HP-= 4;
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest