why my code did't work?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

why if use

else:
    miss_damage_display = true

it wont work, but if use

if ad_on_off == true:
    if final_ad_damage >= 1:
        hp -= final_ad_damage
        ad_damage_display = ad_on_off
        damage_type = final_ad_damage
        
        if crit_on_off ==true:
            if crit_random_change <= crit_chance:
                hp -= crit_damage_value
                crit_damage_display = crit_on_off
                damage_type = crit_damage_value
    if final_ad_damage <= 0:
        miss_damage_display = true
    
    
elif magic_on_off == true:
    if final_ap_damage >= 1:
        hp -= final_ap_damage
        magic_damage_display = magic_on_off
        damage_type = final_ap_damage
    if final_ap_damage <= 0:
        miss_damage_display = true

it will work?
does my “else” should have meaning like if not 1 or obove 1

:bust_in_silhouette: Reply From: supper_raptor

this means final_ad_damage is 0 or less

if final_ad_damage <= 0:
    miss_damage_display = true

but if you use else with

if final_ad_damage >= 1:

It means it will include values less than 1 , It will also include values like 0.99 ,0.5 …
so it may be the reason of failure.

:bust_in_silhouette: Reply From: jgodfrey

Your question is a little vague, but I assume you’re trying to understand the difference between these two pieces of code in the context of the rest of the code:

else:
    miss_damage_display = true

… and …

if final_ad_damage <= 0:
    miss_damage_display = true

This block will process everything where final_ad_damage is greater or equal to 1:

if final_ad_damage >= 1:

So, the two lines of code in question are left to process anything else. So, cases where final_ad_damage < 1.

In the case of the first line in question (the else line), it processes everything that’s not processed by the initial if block. However, the second line in question (the if line), it only fires when final_ad_damage <= 0.

So, it does not run when final_ad_damage is greater than zero, but less than one. That’s the real difference between the two lines.

Again, else handles everything that’s not handled by the top if, but the 2nd if only handles a portion of the remaining cases…