Health

Lingesh7

  • Posts: 54
I have made a behaviour for health. (pls see pic) The problem is that when it collides with an enemy the hp instead of decreasing by 1 it just directly goes to 0. I also made a text behaviour for the scene to display the hp. When the scene is loaded it shows 10 but once it collides with an enemy it directly changes to 0. Is there any way to fix this? (I know about the Health behaviour on forge but it is too complicated and i dont understand much of it. So i want to make my own) Pls help. If there is no way out (99% impossible) can someone simplify the health behaviour and explain it to me. Thanks in advance :P

PhilIrby

  • Posts: 545
I would suspect you are having multiple collisions with the enemy.  Do a forum search for this and you will find a number of suggestions to prevent this.           

dtrungle

  • Posts: 1938
---
When self hits enemy

If canBeHit == true
  set canBeHit to false
  set HP to (HP - 1)
  set delayFlag to true
End
---

---
When updating

If delayFlag == true
  -set delayFlag to false
  Do after 0.1 seconds
    -set delayCounter to (delayCounter + 1)
    If delayCounter >= 10
      -set delayCounter to 0
      -set canBeHit to true
    Otherwise
      -set delayFlag to true
    End
End
---

Defaults
  canBeHit == true
  delayFlag == false
  delayCounter == 0

Also, if your collision box has multiple boxes, this might not work. Test it out and let us know.

Lingesh7

  • Posts: 54
It works but as PhilIrby said i am having multiple collisions with it-if I just stay there the hp goes like 9,8,7,6,...0 and then it dies. How can I solve this multiple collision? (also in the end of your when updating i added if player hp<=0  kill self otherwise the hp went on to minus)Main question how do i solve multiple collisions

chrizt

  • Posts: 345
its not multiple collision. the collision block checking for collision every frame i assume. actually it was decreasing by 1 like u want, but i went too fast. try to put timer block in the collision block
need help with behavior? game design? graphic design? just contact me
skype : christian.atin
email : christianatin27@gmail.com

Lingesh7

  • Posts: 54
Using the same behaviour as dtrungle said, may i know where the timer for the collision block must be put?

chrizt

  • Posts: 345
begin from the outer block collision>timer>set hp -1
need help with behavior? game design? graphic design? just contact me
skype : christian.atin
email : christianatin27@gmail.com

Lingesh7

  • Posts: 54
Sorry I dont understand much   :-[   :'(   
Can you please make a picture of where the timer will be placed
Again thanks in advance

Lingesh7

  • Posts: 54
A snapshot of the behaviour is what i meant

Innes

  • *
  • Posts: 1960
There's an entry in my blog that explains some of the options to solve this problem...

http://www.thestencylblog.com/2012/06/16/stencyl-events-do-please/

« Last Edit: November 16, 2020, 10:58:50 pm by Justin »
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

Lingesh7

  • Posts: 54
Thanks All! Just one last question. The behaviour I (see pic) made is working. Will it have any problems later on? Or do i have to follow dtrungle's method. If I have to follow his method where exactly do i place the do after n seconds block?

dtrungle

  • Posts: 1938
What you have there seems fine. Your behavior will allow your main actor to be damaged once every second.

Lingesh7

  • Posts: 54
A very small problem. I have levels for my game and when I go to the next level, the HP resets back to 10. How do i continue with the same HP?

dtrungle

  • Posts: 1938
Remove the 'when created' event, the thing that sets HP to 10. Go into game settings and look for it in GA, set the initial value to 10 there.

chrizt

  • Posts: 345
you need to set up a game attribute for that. any local attribute will reset its value once u leave scene/reload while Game attribute will store the value till you close the game
need help with behavior? game design? graphic design? just contact me
skype : christian.atin
email : christianatin27@gmail.com