# Desert Combat (python)

**URL:** <https://discourse.codecombat.com/t/desert-combat-python/29244>\
**Category:** Level Help\
**Created:** [June 8, 2021, 3:01am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244 "2021-06-08T03:01:00Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [June 8, 2021, 3:01am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/1 "2021-06-08T03:01:00Z")

</div>

Here’s my code, I’m stuck.

```python
# while-loops repeat until the condition is false.

ordersGiven = 0
while ordersGiven < 5:
    # Move down 10 meters.
    hero.moveXY(10, -10)
    # Order your ally to "Attack!" with hero.say
    # They can only hear you if you are on the X.
    hero.say("Attack!")
    # Be sure to increment ordersGiven!
    ordersGiven += 1
while True:
    enemy = hero.findNearestEnemy()
    # When you're done giving orders, join the attack.
    if enemy:
        hero.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![Hydrobolic](https://avatars.discourse-cdn.com/v4/letter/h/e47c2d/32.png) [@Hydrobolic](https://discourse.codecombat.com/u/Hydrobolic)\
**Post date:** [June 8, 2021, 3:41am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/2 "2021-06-08T03:41:04Z")

</div>

The key to this level to to use relative coordinates. Rather than moving to an absolute position — `hero.moveXY(10, -10)` — you want to move to a position relative to where your hero currently is.

`hero.moveXY(hero.pos.x, hero.pos.y)` moves exactly to where your hero is (not at all); how can you modify it?

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [June 8, 2021, 11:37am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/3 "2021-06-08T11:37:20Z")

</div>

> [@enPointe77](#):
>
> `hero.moveXY(10, -10)`

Yes, like Hydrobolic said, You don’t want to move to a specific position. In this case, your hero will move to (10,-10) and say “Attack” 5 times. You want to move 10 meters from your current position (hero.pos.x, hero.pos.y).

---

<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:** [June 8, 2021, 3:32pm UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/4 "2021-06-08T15:32:09Z")

</div>

I’ll try that, thanks!

---

<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:** [June 11, 2021, 4:18am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/5 "2021-06-11T04:18:41Z")

</div>

It still doesn’t work (I’ve been having a difficult time copying my code, so I’m sending a pic):

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/6/b/6bd5e45d2e127cac988c0706c7e01dc66fe19ea2.jpeg)

---

<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:** [June 11, 2021, 4:22am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/6 "2021-06-11T04:22:29Z")

</div>

This is the link if you need it:  
[CodeCombat - Coding games to learn Python and JavaScript](https://codecombat.com/play/level/desert-combat)?

---

<div class="post-metadata">

**Author:** ![Hydrobolic](https://avatars.discourse-cdn.com/v4/letter/h/e47c2d/32.png) [@Hydrobolic](https://discourse.codecombat.com/u/Hydrobolic)\
**Post date:** [June 11, 2021, 6:25am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/7 "2021-06-11T06:25:05Z")

</div>

Right now you’re commanding your hero to move to _exactly_ its own position, which of course does nothing. You want to move to a position _relative_ to your hero.

Say there’s a point at `(30, 50)`. The point 10 units below it is `(30, 50 - 10)`, or `(30, 40)`. This can be generalized to any point, where the point 10 units below `(x, y)` is `(x, y - 10)`.

Your `hero` is at the point `(hero.pos.x, hero.pos.y)`, and you want to apply the above.

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [June 11, 2021, 3:15pm UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/8 "2021-06-11T15:15:07Z")

</div>

You move to your hero’s position, which will always be the same unless you move. You need to move 10m below your current position (hero.pos.y - 10). You need to use the same x position though (hero.pos.x).

---

<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:** [June 15, 2021, 1:26am UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/9 "2021-06-15T01:26:17Z")

</div>

Thanks guys, I got it.

---

<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:** [June 15, 2021, 1:27pm UTC](https://discourse.codecombat.com/t/desert-combat-python/29244/10 "2021-06-15T13:27:06Z")

</div>

Closed on June 15, 2021, 1:27pm UTC

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