In Backwoods Forest having trouble clearing the bonus stages.
What is wrong with my code? It casts lightning bolt once and doesn’t do it again even though it says it’s ready.
chainReady = hero.canCast("chain-lightning")
lightningReady = hero.canCast("lightning-bolt")
def chainlightning():
target = hero.findNearestEnemy()
if target:
distance = hero.distanceTo(target)
if distance < 10 and chainReady:
hero.cast("chain-lightning",target)
else:
hero.attack(target)
pass
def lightningbolt():
target = hero.findNearestEnemy()
if target:
if lightningReady:
hero.say("Pikachu")
hero.cast("lightning-bolt",target)
else:
hero.cast("chain-lightning",target)
pass
while True:
target = hero.findNearestEnemy()
if target:
distance = hero.distanceTo(target)
if target.type == "munchkin":
chainlightning()
if target.type != "munchkin" and distance > 5:
lightningbolt()
if target.type != "munchkin" and distance < 5:
hero.say("Too Close")
if hero.health < 75:
hero.cast("regen",hero)
Aya
March 12, 2022, 1:01pm
2
Welcome to the forum @Knighthawk17 ! This is a friendly place where you can ask help on levels, report bugs, or just chat with other coders! Don’t forget to read the guidelines if you haven’t yet. Have a great time!
Please format all your code with this button so we can help you:
Woohooo figured it out! If anyone wants to use my code as reference
def chainlightning():
chainReady = hero.canCast("chain-lightning")
target = hero.findNearestEnemy()
if target:
distance = hero.distanceTo(target)
if distance < 10 and chainReady:
hero.cast("chain-lightning",target)
else:
hero.attack(target)
pass
def lightningbolt():
lightningReady = hero.canCast("lightning-bolt")
target = hero.findNearestEnemy()
if target:
if lightningReady:
hero.say("Pikachu")
hero.cast("lightning-bolt",target)
else:
if hero.health < 75:
hero.moveXY(19,26)
hero.cast("chain-lightning",target)
hero.moveXY(11,45)
else:
hero.attack(target)
pass
while True:
target = hero.findNearestEnemy()
if target:
if target.type == "ogre":
hero.moveXY(6,45)
distance = hero.distanceTo(target)
if target.type == "munchkin":
chainlightning()
if target.type != "munchkin":
lightningbolt()
if hero.health < 80:
hero.cast("regen",hero)
Hello! So glad you figured it out! But I do request that you remove your working code. If others need help, and find your code, they won’t have learned anything because they’d be given the code. And CodeCombat is about learning and figuring out what’s wrong.
1 Like
system
Closed
March 18, 2022, 3:00am
5
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.