Is this code of "Learn the Basics of Verse" ok?

On learn-code-basics-7-practice-time-in-verse there is a code that not make sense to me

Is says that “The effect of this code is that it will give the player a second chance if they drink a potion that would normally eliminate them.”

88f403907d7303df3a5ffb98e8ae9e2a

but on the else if you are giving the players more than a second chance, for example:

PlayerHealth = 79.0
after the function Player will be 78.0 as you are only decresing PlayerHealth by 1.0. The player can continue to “drink” the potion 77 more times.

Should it not be “set PlayerHealth = MinHealth”?

it seams the code in the next lecture is being used in a function that makes sense :grin:

Yes, the code is ok.

image

The purple circle its a subtraction.

  • Player has 100 hp.
    – Your verse code has “PlayerHealth: 100” So those two has synced health.

  • You deal 120 damage.

  • Verse PlayerHealth is now -20.
    – Player still has 100 hp.

And then you send:

        else if (PlayerHealth > MinHealth):
            # Give player one more chance if their health is low
            return PlayerHealth - MinHealth

Because -20 is less than 100.

Everything ok at this point?

What is happening its FortniteCharacter.Damage(DamageToDo) it’s doing this:

FortniteCharacter.Damage(-20 - 1)

In other words: 100 - (-20 - 1) = 121.

Remember: - multiplied by - = +

So, why do you have “1” and not “121”?

The .Damage() says: Setting Amount to less than 0 will cause no damage

So (this part is not exactly correct, but hope you get the point):

  • FortniteCharacter.Damage(DamageToDo)
    100 - (-20 - 1) = 0 (Because can’t be lower than 0)
    0 - ( 0 - 1 ) = 1

I SUPPOSE. IF ISN’T THIS, I DON’T KNOW. THERE’S NO OTHER WAY(???)