Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sbenitezb | |
Old Version | Published before Godot 3 was released. |
Hi, I have the following code that’s failing with error
Invalid operands ‘Nil’ and ‘float’ in operator ‘<=’.
func apply_damage():
var rem = 0.0
var pureDamage = baseDamage * damageMultiplier * accuracy
if health == null: return false
if shield != null:
rem = shield.take_damage(get_parent(), pureDamage * shieldPenetrationMultiplier)
if rem <= 0.0 and armor != null:
rem = armor.take_damage(get_parent(), pureDamage * armorPenetrationMultiplier)
if rem <= 0.0:
if health.take_damage(get_parent(), pureDamage) <= 0.0:
# Target is dead
release_target()
return false
return true
It fails the check where it says ‘if rem <= 0.0 and armor != null:’. For some reason variable rem is not initialized… The debugger show ‘rem’ as empty.