Help adding HP

Non-platform specific questions.

Help adding HP

Postby beginnerirvaz » Thu Sep 15, 2011 10:56 pm

I have followed the FAQ that describes how to add HP to my player but I can't get it to work. COuld somebody let me no if I am on the right track.

I tried to add a actor variable called Hp, I done this by going to script, global code, typed HP;, I clicked variables, add, called it HP, changed global to actor variable, and finally add.

I then selected my player, add, create actor, script editor, and typed HP=3;

Then I selected my enemy, add, collision, any side and player, add action, script editor, then typed
HP--;
DestroyActor("Collide Actor");
If(HP==0)
{
DestroyActor("Event Actor");
}

If any can see what I have done wrong that would be great

Thanks
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Help adding HP

Postby ikarus » Fri Sep 16, 2011 12:23 am

Then I selected my enemy, add, collision, any side and player, add action, script editor, then typed
HP--;
DestroyActor("Collide Actor");
If(HP==0)
{
DestroyActor("Event Actor");
}

If you are adding this to your enemy's collision then it's a bit backwards. First "Collide Actor" is a reference to what it hits so if this hits your player it'll automatically destroy it. You should switch "Collide Actor" and "Event Actor". Also Actor variables are common to all actors, meaning your enemy has its own HP variable too. So you should make it "collide.HP--;" and "if(collide.HP==0)" because otherwise you're just messing with the enemy's personal HP.
I'm not entirely sure I know what you're trying to do though, hope it helps. Here's some cut and paste code for ya
collide.HP--;
DestroyActor("Event Actor");
if(collide.HP==0)
{
DestroyActor("Collide Actor");
}


[edit]
Just saw your "if" is capitalized, don't know if that's how it is in your code but that will throw an error.
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: Help adding HP

Postby beginnerirvaz » Fri Sep 16, 2011 10:15 am

Thanks for the help, really approciate it.
I probably should of added I would like my player to have 3lives and he looses 1 life if he touches a enemy. I will try the above when I finish work and let you know what happens.

Thanks
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Help adding HP

Postby ikarus » Fri Sep 16, 2011 2:31 pm

It should still work, just make sure to set "HP = 3;" in your player's create actor event ^-^
>>>>>>>>>>>>>>>>>>>>> http://www.code1011.com <<<<<<<<<<<<<<<<<<<<<<<
ikarus
 
Posts: 143
Joined: Fri Aug 12, 2011 3:06 am
Score: 11 Give a positive score

Re: Help adding HP

Postby beginnerirvaz » Sun Sep 18, 2011 12:41 pm

Hi
I've tried what you said but It still doesn't seem to be working. I have obviously done something wrong but I've tried everything...

At the moment I have a player that can move and an enemy. When the player collides with the enemy he dies. I followed the platform game tutorial on this site.

I would like my player to have a HP of 3 and each time he collides with the enemy It decrements by 1.

Would you be so kind as to helping me step by step, each step exactly what I should be clicking and typing.

Thanks for your help.
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Help adding HP

Postby savvy » Sun Sep 18, 2011 2:41 pm

here we go, demo... you know how it works, same as what i told you to do but you went wrong somewhere...

savvy
Attachments
hptut.zip
HP DEMO
(33.03 KiB) Downloaded 85 times
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Help adding HP

Postby beginnerirvaz » Sun Sep 18, 2011 5:55 pm

Thanks to everyone for your help.

thanks savvy your tutorial, I now have hp!
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest