Hello,
I am used to Java type of syntax but I started CodeCombat in Python and got used to it. I did two versions of the codes and noticed one worked and the other didn’t. I couldn’t make sense of why the other version couldn’t work. Take a look and please shed some lights. Thank you.
working
> loop:
> currentHealth = self.health
> healingThreshold = self.maxHealth / 2
> # If your current health is less than the threshold,
> # move to the healing point and say, "heal me".
> # Otherwise, just attack enemies.
> enemy = self.findNearestEnemy()
> if currentHealth < healingThreshold :
> self.moveXY(65, 46)
> self.say("heal me")
> **elif enemy :**
> self.shield()
> self.attack(enemy)
> self.attack(enemy)
> self.attack(enemy)
not working
> loop:
> currentHealth = self.health
> healingThreshold = self.maxHealth / 2
> # If your current health is less than the threshold,
> # move to the healing point and say, "heal me".
> # Otherwise, just attack enemies.
> enemy = self.findNearestEnemy()
> if currentHealth < healingThreshold:
> self.moveXY(65, 46)
> self.say("heal me")
**else:**
self.shield()
self.attack(enemy)
self.attack(enemy)
self.attack(enemy)
Notice the Bold part in else portion.
My humans didn’t survive in the nonworking one. I looked up the documentation and changed it to “elif enemy”.
What was interesting was, the error message for not working one tells me there was no target for me the attack. How so, enemy was defined outside of the if/else loop. So I suppose it would work.
any ideas?
Merry Christmas by the way!