# Find a problem about the stage: ThunderHooves, Sarven

**URL:** <https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681>\
**Category:** Uncategorized\
**Created:** [February 13, 2015, 3:51am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681 "2015-02-13T03:51:56Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 13, 2015, 3:51am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/1 "2015-02-13T03:51:56Z")

</div>

I don’t know what’s problem with my code, but every time I run it, my character always build two fences when he passing by the second yak, then got himself stucked…  
What should I do to make it right?  
I’m sorry if my expression has any problem. English is not my native language but I’m learning it  
Here is my code:

```
loop:
    yak = self.findNearestEnemy()
    if yak:
        # If the yak is above you, build a fence 10m below it.
        if yak.pos.y > self.pos.y:
            self.buildXY("fence", yak.pos.x, yak.pos.y)
        # If the yak is below you, build a fence 10m above it.
        if yak.pos.y < self.pos.y:
            self.buildXY("fence", yak.pos.x, yak.pos.y + 10)
        pass
    else:
        # Move right 10m towards the oasis.
        self.moveXY(self.pos.x + 10, self.pos.y)
        pass
```

---

<div class="post-metadata">

**Author:** ![eiler13](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@eiler13](https://discourse.codecombat.com/u/eiler13)\
**Post date:** [February 13, 2015, 4:03am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/2 "2015-02-13T04:03:22Z")

</div>

You are on the right track. I see “+10”. Maybe you also want “-10” somewhere?

---

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 13, 2015, 5:03am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/3 "2015-02-13T05:03:47Z")

</div>

Right! That’s a fault I made. Thanks:)  
But the second yak come from bottom of screen, so though I fixed my code, the problem still happened as usual…  
 ![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2046/f12d7b0e3af43b3e.png)

---

<div class="post-metadata">

**Author:** ![Thelonious](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/thelonious/32/2048_2.png) [@Thelonious](https://discourse.codecombat.com/u/Thelonious)\
**Post date:** [February 13, 2015, 5:10pm UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/4 "2015-02-13T17:10:08Z")

</div>

Hey man, what’s up? try with differents boots, I think the problem is the speed of your character.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [February 14, 2015, 3:45am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/5 "2015-02-14T03:45:53Z")

</div>

no I dont think that is it I think he needs to build the fences closer to the yak and farther from Tharin

---

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 14, 2015, 8:02am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/6 "2015-02-14T08:02:00Z")

</div>

You’re right! It is speed’s problem. But I’ve already equiped the best boot that I unlock yet. So I change my character to Hanzo. and problem solved. Thanks!

---

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 14, 2015, 8:04am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/7 "2015-02-14T08:04:13Z")

</div>

I’ve tried that by change the parameter of distance, but it won’t help…so I changed a faster character Hanzo. then problem solved. Thanks anyway

---

<div class="post-metadata">

**Author:** ![eiler13](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@eiler13](https://discourse.codecombat.com/u/eiler13)\
**Post date:** [February 14, 2015, 3:16pm UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/8 "2015-02-14T15:16:35Z")

</div>

Glad you solved it. You don’t need hanzo but maybe you need the soft leather boots which are +2.5 on speed instead of +2 like other boots.

Another thing is that you could make your last “if” an “elif”. (my code is exactly like yours, except for that). Then you could only build a fence above or below, not both, regardless of speed. I wonder if b/c you were going too slow that you were finding the second nearest yak (not directly above you but rather above and to the right).

btw, “pass” is just a placeholder for an empty loop. You can take those out once you fill in with your real code.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [February 15, 2015, 12:46am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/9 "2015-02-15T00:46:29Z")

</div>

oh I see it now you are building the fences on both sides if you only build them on one you would not have the problem of getting stuck

---

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 15, 2015, 8:01am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/10 "2015-02-15T08:01:04Z")

</div>

Thanks for the tips of code. I’ve tried it and it does work better then before. But this time some strange things happened.  
When I use Tharin with soft leather boots, he missed the third yak and just go ahead. then hit by that yak. But things went right as long as I equipped boots which +2 on speed. I have no idea about what’s wrong with it: (  
here’s what happened:  
 ![](https://sea2.discourse-cdn.com/flex016/uploads/codecombat/2051/9520f472da69b6be.png)

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![MrKauz](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MrKauz](https://discourse.codecombat.com/u/MrKauz)\
**Post date:** [February 15, 2015, 8:03am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/11 "2015-02-15T08:03:20Z")

</div>

Yeah. I tried “elif”, then voila, problem solved:)

---

<div class="post-metadata">

**Author:** ![DORRITO](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dorrito/32/2108_2.png) [@DORRITO](https://discourse.codecombat.com/u/DORRITO)\
**Post date:** [June 26, 2015, 8:49am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/12 "2015-06-26T08:49:59Z")

</div>

Bringing this one up again, I am pretty sure I have the correct code, but I’m posting it here just in case, (gotta look up how to fuzz it out real quick).

My problem is, after the first yak who I successfully block whether it comes from the top or the bottom, my character runs past the second yak, ( whom ALWAYS comes from the bottom no matter how many times I’ve reloaded the page and resubmit) and I head to the bottom of the 2nd yak’s area, where I keep building walls.

To me, it looks like my character is targeting the scorpion, or bones, or something down there that can be identified as an enemy. (I don’t know if they can be or not, I’m just trying to make sense of it) If so, I’ve forgotten how to identify enemies, will targeting the yaks only fix that?

Otherwise, may I get some help as to where my code may be wrong? I’ve also tried elif on the 2nd if, and a few other changes, and I don’t have access to hanzo or other boots right now to try if a different speed will help.

code: (if indents are off, it’s because I screwed them up while putting them in here)

> **spoiler**
>
> ```python
> # Get to the oasis,
> # fencing off paths with yaks on them as you go.
> loop:
> yak = self.findNearestEnemy()
> if yak:
> # A yak is above you if its y is greater than your y.
> # If the yak is above you, build a fence 10m below it.
>         
> if yak.pos.y > self.distanceTo(yak):
> self.buildXY("fence", yak.pos.x, yak.pos.y - 10)
> # If the yak is below you, build a fence 10m above it.
> if yak.pos.y < self.distanceTo(yak):
> self.buildXY("fence", yak.pos.x, yak.pos.y + 10)
>         
> else:
> # Move right 10m towards the oasis.
>        
> self.moveXY(self.pos.x +10, self.pos.y) 
> 
> ```

---

<div class="post-metadata">

**Author:** ![DORRITO](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dorrito/32/2108_2.png) [@DORRITO](https://discourse.codecombat.com/u/DORRITO)\
**Post date:** [June 26, 2015, 8:50am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/13 "2015-06-26T08:50:37Z")

</div>

welps, cant figure out how to work spoiler apparently, even when looking at examples.

---

<div class="post-metadata">

**Author:** ![ant](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ant/32/3362_2.png) [@ant](https://discourse.codecombat.com/u/ant)\
**Post date:** [June 26, 2015, 9:06am UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/14 "2015-06-26T09:06:54Z")

</div>

Well, you’re comparing apples to pears:

```python
if yak.pos.y > self.distanceTo(yak):

```

- `yak.pos.y` is the yak’s y-coordinate
- `self.distanceTo(yak)` is the distance between you and the yak

You need to compare your position with the yak’s position:

```python
if yak.pos.y > self.pos.y:

```

* * *

Furthermore, the second `if` statement could be simply replaced by an `else`:

```python
if yak.pos.y > self.pos.y:
    # do this
else: # when yak.pos.y <= self.pos.y:
    # do that

```

---

<div class="post-metadata">

**Author:** ![DORRITO](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dorrito/32/2108_2.png) [@DORRITO](https://discourse.codecombat.com/u/DORRITO)\
**Post date:** [June 26, 2015, 6:17pm UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/15 "2015-06-26T18:17:35Z")

</div>

Yup, first thing was the prob, and now I understand. Funny how 30 mins of combing over that code yielded nothing. I’m in for a bright future!

Thanks Ant, I hope your movie does well!

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [June 27, 2015, 10:17pm UTC](https://discourse.codecombat.com/t/find-a-problem-about-the-stage-thunderhooves-sarven/2681/16 "2015-06-27T22:17:03Z")

</div>

the problem is that ``` and [spoiler] don’t like each other. so you have to use [details=blahblah] if you want to have nicely formatted code in your spoiler. (I editted your mesage to use details)
