# The Trials stuck

**URL:** <https://discourse.codecombat.com/t/the-trials-stuck/6108>\
**Category:** Adventurer\
**Created:** [December 15, 2015, 4:26pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108 "2015-12-15T16:26:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaind](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@Kaind](https://discourse.codecombat.com/u/Kaind)\
**Post date:** [December 15, 2015, 4:26pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108/1 "2015-12-15T16:26:39Z")

</div>

I need some help with my code. He just stands there? Any ideas?

```
loop:
    closestEnemy = None
    minDistance = 150
    enemyIndex = 0
    enemies = self.findEnemies()
    mushrooms = self.findItems()
    mushroom = self.findNearest(mushrooms)
    if closestEnemy:
        currentEnemy = enemies[enemyIndex]
        enemyIndex += 1
        currentDistance = self.distanceTo(currentEnemy)
        if closestEnemy:
            while closestEnemy.health > 0:
                if closestEnemy.health > 150:
                    if self.isReady("power-up"):
                        self.powerUp()
                    elif self.isReady("bash"):
                        self.bash(closestEnemy)
                    else:
                        self.attack(closestEnemy)
                else:
                    self.attack(closestEnemy)
        elif mushroom:
            self.move(mushroom.pos)
    elif self.pos.y > 100:
        if self.pos.x > 90:
            self.moveXY(75, 125)
        if self.pos.x < 40:
            self.moveXY(100, 125) 
        if self.pos.x > 50 and self.pos.x <= 90:
            newEnemy = self.findNearest(self.findEnemies())
            if not newEnemy:
                self.move({"x": 55, "y":115})
                self.moveXY(27, 121)
                self.moveXY(56, 122)
                self.moveXY(45, 96)
                self.move({"x": 45, "y":70})
                self.moveXY(80, 70)
            else:
                pass
```

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [December 15, 2015, 5:17pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108/2 "2015-12-15T17:17:28Z")

</div>

Please indent your code correctly by highlighting it and clicking the \</\> button. Reading the FAQ before posting can be helpful. 😉

---

<div class="post-metadata">

**Author:** ![Kaind](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@Kaind](https://discourse.codecombat.com/u/Kaind)\
**Post date:** [December 15, 2015, 5:23pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108/3 "2015-12-15T17:23:20Z")

</div>

Oh sorry I didn’t know how to indent and I am really busy

---

<div class="post-metadata">

**Author:** ![GundericusTheMighty](https://avatars.discourse-cdn.com/v4/letter/g/bbce88/32.png) [@GundericusTheMighty](https://discourse.codecombat.com/u/GundericusTheMighty)\
**Post date:** [December 15, 2015, 5:26pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108/4 "2015-12-15T17:26:01Z")

</div>

I see your problem. You define `closestEnemy` as `None`, then never redefine it as anything else. For this reason, `closestEnemy` is never true, so the `if`-statement never runs.

---

<div class="post-metadata">

**Author:** ![Kaind](https://avatars.discourse-cdn.com/v4/letter/k/ecae2f/32.png) [@Kaind](https://discourse.codecombat.com/u/Kaind)\
**Post date:** [December 15, 2015, 6:07pm UTC](https://discourse.codecombat.com/t/the-trials-stuck/6108/5 "2015-12-15T18:07:40Z")

</div>

oh oops thank you so much I’ll fix that and see if it works.
