Could you go into if (damage >= currentHealth) { is for? Won't this lead to the player dying prematurely - while...

Could you go into if (damage >= currentHealth) { is for? Won't this lead to the player dying prematurely - while still having 10 health?
  • Jonathan Gonzalez(jgonzalez) replied
    If the damage amount is greater than our current health then we automatically die. How are you getting 10 health? If the damage amount is say 11 and our current health is 10, then we are going to die because the damage amount is greater than the health. If you're seeing something different let me know.
  • krystman replied
    If I run this code I lose health in 10 unit increments until it reaches 20. If I get damaged while at 20 I skip going down to 10. Instead I go to 0 and die immediately. I believe the same happens in the fast-forwarded video above.
  • Jonathan Gonzalez(jgonzalez) replied
    I just tried it out myself to see what you were talking about. I'm not entirely sure why it jumps like that, but removing the "=" seems to fix it. The reasoning for using that was in case the damage was exactly the same amount as the currentHealth we'd also die, but it seems it causes an issue with it. Nonetheless just the ">" works as well. If you know why this happened I'd like to know as well.
  • krystman replied
    I think the problem is that we do this check AFTER we already subtracted damage from health. So we kinda we apply double the damage if it is enough to kill the player, right? Which is why that if-statement confuses me. If we leave this whole statement out, shouldn't the HealthStatus() function figure out that the player has died anyway?
  • Jonathan Gonzalez(jgonzalez) replied
    The if statement was included to prevent going into a negative state but I could've also just added "currentHealth = 0" up above where we check to see if our health is equal to or below health. Regarding the double deduction, I believe you're right. We're deducting the damage amount and also checking the value of "damage" . Even if it was placed above the deduction section it'll do the same thing.