# Need help on Backwoods Treasure not really sure whats wrong?

**URL:** <https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949>\
**Category:** Uncategorized\
**Created:** [March 8, 2016, 5:04am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949 "2016-03-08T05:04:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sasha15757](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sasha15757/32/3783_2.png) [@sasha15757](https://discourse.codecombat.com/u/sasha15757)\
**Post date:** [March 8, 2016, 5:04am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/1 "2016-03-08T05:04:26Z")

</div>

Again not really sure whats wrong with the code my hero IS collecting coins  
and killing enemies at the same time. But, then the moment the coins run out in that grove he stops attacking enemies or moving. Please help! I have strugled with this lvl for at least a month now! : (

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/4/420e1ad48e25e82c75dcd06f39faffd7e3e9349c.png)

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [March 8, 2016, 5:23am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/2 "2016-03-08T05:23:56Z")

</div>

You are trying to access a property of `item` before you check if it’s actually there. Move the coordinate definitions inside the `if item:` block.

---

<div class="post-metadata">

**Author:** ![baomatai](https://avatars.discourse-cdn.com/v4/letter/b/a9a28c/32.png) [@baomatai](https://discourse.codecombat.com/u/baomatai)\
**Post date:** [March 8, 2016, 3:20pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/3 "2016-03-08T15:20:46Z")

</div>

You should incorporate the use of flags to move to the center so you can find the nearest coin from there.

---

<div class="post-metadata">

**Author:** ![Alexbrand](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Alexbrand](https://discourse.codecombat.com/u/Alexbrand)\
**Post date:** [March 8, 2016, 3:54pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/4 "2016-03-08T15:54:36Z")

</div>

Also you can use

> if not item:
> 
> > ```
> > moveXY(x,y)
> > 
> > ```

instead of using flag, to define position, where your hero can see coin. I prefer this way because I don’t like manual usage of flags and try to avoid that if it’s possible) Good luck!

---

<div class="post-metadata">

**Author:** ![ARasberrypy-thon](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@ARasberrypy-thon](https://discourse.codecombat.com/u/ARasberrypy-thon)\
**Post date:** [March 8, 2016, 4:55pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/5 "2016-03-08T16:55:45Z")

</div>

Or, you should use a distance variable, like:

```python
if item:
    distance = distanceTo(item)
if distance < 20:
moveXY(x, y)

```

Or you could use flags.

---

<div class="post-metadata">

**Author:** ![CmcsMinecraft123](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@CmcsMinecraft123](https://discourse.codecombat.com/u/CmcsMinecraft123)\
**Post date:** [March 11, 2016, 1:58am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/6 "2016-03-11T01:58:19Z")

</div>

Uhh. Can u guys please type the real code that makes u win? I have been stuck on this for hours

---

<div class="post-metadata">

**Author:** ![ChronistGilver](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chronistgilver/32/3778_2.png) [@ChronistGilver](https://discourse.codecombat.com/u/ChronistGilver)\
**Post date:** [March 11, 2016, 2:02am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/7 "2016-03-11T02:02:25Z")

</div>

No, we most definitely cannot type the real code that makes you win. That goes against our forum-policy and will prevent any of the future readers from learning a thing.

---

<div class="post-metadata">

**Author:** ![CmcsMinecraft123](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@CmcsMinecraft123](https://discourse.codecombat.com/u/CmcsMinecraft123)\
**Post date:** [March 11, 2016, 4:20am UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/8 "2016-03-11T04:20:15Z")

</div>

Never mind finally got it!!!

---

<div class="post-metadata">

**Author:** ![ARasberrypy-thon](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@ARasberrypy-thon](https://discourse.codecombat.com/u/ARasberrypy-thon)\
**Post date:** [March 12, 2016, 5:20pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/9 "2016-03-12T17:20:32Z")

</div>

This made me laugh. 🙂

---

<div class="post-metadata">

**Author:** ![sasha15757](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sasha15757/32/3783_2.png) [@sasha15757](https://discourse.codecombat.com/u/sasha15757)\
**Post date:** [March 13, 2016, 8:06pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/10 "2016-03-13T20:06:49Z")

</div>

using if flag does not help tryed did not work:( ! also using else does not work. my hero just gets stuck there where the coins end in that grove

 ![](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/5/59b4e82732a9df32feb4088e8ee738cfad29aa52.png)

---

<div class="post-metadata">

**Author:** ![sasha15757](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sasha15757/32/3783_2.png) [@sasha15757](https://discourse.codecombat.com/u/sasha15757)\
**Post date:** [March 13, 2016, 10:08pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/11 "2016-03-13T22:08:54Z")

</div>

i think that could work thx! 🙂

---

<div class="post-metadata">

**Author:** ![ARasberrypy-thon](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@ARasberrypy-thon](https://discourse.codecombat.com/u/ARasberrypy-thon)\
**Post date:** [March 17, 2016, 5:39pm UTC](https://discourse.codecombat.com/t/need-help-on-backwoods-treasure-not-really-sure-whats-wrong/6949/12 "2016-03-17T17:39:41Z")

</div>

This is because you haven’t checked if there is an item. If there is no item, it will attempt to define a `pos` that doesn’t exist. Instead you should check `if item:` first.
