# Level - The One Wizard

**URL:** <https://discourse.codecombat.com/t/level-the-one-wizard/32334>\
**Category:** Level Help\
**Created:** [March 12, 2022, 12:48pm UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334 "2022-03-12T12:48:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Knighthawk17](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Knighthawk17](https://discourse.codecombat.com/u/Knighthawk17)\
**Post date:** [March 12, 2022, 12:48pm UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334/1 "2022-03-12T12:48:48Z")

</div>

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.

```python
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)

```

---

<div class="post-metadata">

**Author:** ![Aya](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/aya/32/42680_2.png) [@Aya](https://discourse.codecombat.com/u/Aya)\
**Post date:** [March 12, 2022, 1:01pm UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334/2 "2022-03-12T13:01:38Z")

</div>

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](https://discourse.codecombat.com/t/welcome-to-codecombat-discourse-forums/15601) if you haven’t yet. Have a great time!

Please format all your code with this button so we can help you:

 ![Screenshot 2021-08-24 12.35.14](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/3/c/3c215fa51daac29c4dee042c92f597e6b9a39662.png)

---

<div class="post-metadata">

**Author:** ![Knighthawk17](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Knighthawk17](https://discourse.codecombat.com/u/Knighthawk17)\
**Post date:** [March 12, 2022, 6:37pm UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334/3 "2022-03-12T18:37:16Z")

</div>

Woohooo figured it out! If anyone wants to use my code as reference

```python
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)

```

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [March 12, 2022, 8:03pm UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334/4 "2022-03-12T20:03:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [March 18, 2022, 3:00am UTC](https://discourse.codecombat.com/t/level-the-one-wizard/32334/5 "2022-03-18T03:00:49Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
