Same actor with individual health/life. How to do this?

Non-platform specific questions.

Same actor with individual health/life. How to do this?

Postby mcavalcanti » Thu Aug 18, 2011 9:40 pm

Hi, I created two of the same soldier. Like this:

CreateActor("soldier", "soldier", "(none)", "(none)", 498, 253, false);
CreateActor("soldier", "soldier", "(none)", "(none)", 261, 331, false);

Each one must have his own life value. I suppose I need to use actor variable, but I don't know how. I set the elife (enemy life) variable as actor variable, but it is affecting both soldiers. How to do? Thanks.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby skydereign » Thu Aug 18, 2011 9:55 pm

Well, if it is an actor variable, it shouldn't be changing both. What might be the problem is how you are displaying the variable. For instance if you had 50 cloned actors, that had the actor variable hp. This code would only change the first clone's hp variable.
Code: Select all
clone.hp-=10;


So when you display a variable via a health bar or textNumber, you have to be more specific.
Code: Select all
Actor * c2 = getclone("clone.2");
textNumber = c2->hp;


Now it is much easier if you use the especial actor types (creator, parent, collide). So if you have an hp bar for each soldier you create, put the create actor for the hp bar in the soldiers create actor. That way when you need the hp displayed, you can access the correct clone by using this.
Code: Select all
textNumber = creator.hp;


Now if you want to lower a soldiers hp during a collision (assuming the event belongs to the other actor), you can do this.
Code: Select all
collide.hp-=10;


So to sum that up, it is probably due to you not using actor specific references to the variable.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby schnellboot » Thu Aug 18, 2011 10:17 pm

oh sky was faster
anyway I made a demo for you
Attachments
cloneLife.rar
(375.08 KiB) Downloaded 103 times
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby mcavalcanti » Thu Aug 18, 2011 11:00 pm

Oh, I see. I understood both examples. Thanks. But, please, how can I destroy the textNumber of the soldier who died?
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby skydereign » Thu Aug 18, 2011 11:31 pm

You can use this code to check if the creator is still alive or not. If it isn't, that statement will be true and it will destroy itself. You could also store the index of the created hp display actor, but this one is less involved. You'll probably put it in draw actor with your textNumber call.
Code: Select all
if(getclone(creator.clonename)->cloneindex==-1)
{
    DestroyActor("Event Actor");
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby mcavalcanti » Fri Aug 19, 2011 12:15 am

Hi, skydereign. I'm using the getclone2 function. The schnellboot example was clearer to me. I'm not understanding this last statment you posted. :-(
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby mcavalcanti » Fri Aug 19, 2011 1:48 am

The enemy's life actor is working correctly with the getclone2 function. Actually i'm having problem with creating and destroying this life actor. When i destroy one, i destroy all.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby skydereign » Fri Aug 19, 2011 7:40 am

Well what schnellboot did will work, but isn't as reliable as what I suggested. And in this case using getclone2 like he did is actually more work (2 lines of code, custom function, and Actor*). I changed the draw actor code of the health display to have this code.
Code: Select all
textNumber=creator.elife;


That does exactly the same thing but doesn't rely on the actors having the same cloneindex. Anyway, I also added the code I said to copy paste into the draw event to it. So the full draw event is as follows.
soldierHp -> Draw Actor -> Script Editor
Code: Select all
textNumber=creator.elife;
if(getclone(creator.clonename)->cloneindex==-1)
{
    DestroyActor("Event Actor");
}


And that should work. If for some reason that still wasn't clear, all you need to do is replace soldierHp's draw event with the code above.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby schnellboot » Fri Aug 19, 2011 8:13 am

I didnt know there is "creator"
thanls sky
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Same actor with individual health/life. How to do this?

Postby mcavalcanti » Fri Aug 19, 2011 2:10 pm

Hey, it's working! :D
Thanks for explaining again. I was doing something wrong, but now it's ok. Thank you both! :)
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest