Page 1 of 1
Help adding HP
Posted:
Thu Sep 15, 2011 10:56 pm
by beginnerirvaz
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
Re: Help adding HP
Posted:
Fri Sep 16, 2011 12:23 am
by ikarus
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.
Re: Help adding HP
Posted:
Fri Sep 16, 2011 10:15 am
by beginnerirvaz
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
Re: Help adding HP
Posted:
Fri Sep 16, 2011 2:31 pm
by ikarus
It should still work, just make sure to set "HP = 3;" in your player's create actor event ^-^
Re: Help adding HP
Posted:
Sun Sep 18, 2011 12:41 pm
by beginnerirvaz
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.
Re: Help adding HP
Posted:
Sun Sep 18, 2011 2:41 pm
by savvy
here we go, demo... you know how it works, same as what i told you to do but you went wrong somewhere...
savvy
Re: Help adding HP
Posted:
Sun Sep 18, 2011 5:55 pm
by beginnerirvaz
Thanks to everyone for your help.
thanks savvy your tutorial, I now have hp!