# Drop the Flag Level Help\[SOLVED\]

**URL:** <https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575>\
**Category:** Level Help\
**Created:** [February 22, 2021, 8:57pm UTC](https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575 "2021-02-22T20:57:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giovanni\_Busacca](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/giovanni_busacca/32/20806_2.png) [@Giovanni\_Busacca](https://discourse.codecombat.com/u/Giovanni_Busacca)\
**Post date:** [February 22, 2021, 8:57pm UTC](https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575/1 "2021-02-22T20:57:39Z")

</div>

Hi, I was working on my code and ran into a small problem.  
Here is my code

```python
# Put flags where you want to build traps.
# When you're not building traps, pick up coins!

while True:
    flag = hero.findFlag()
    if flag:
        # How do we get flagX and flagY from the flag's pos?
        # (Look below at how to get x and y from items.)
        self.buildXY("fire-trap", 30, 45)
        self.buildXY("fire-trap", 30, 31)
        self.buildXY("fire-trap", 30, 16)
        
        hero.buildXY("fire-trap", flagX, flagY)
        hero.pickUpFlag(flag)
    else:
        item = hero.findNearestItem()
        if item:
            itemPos = item.pos
            itemX = itemPos.x
            itemY = itemPos.y
            hero.moveXY(itemX, itemY)

```

Here is a screenshot

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/d/7/d7fd0878d9f0c656f5018606142ce69b5b06dd51.jpeg)

---

<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:** [February 22, 2021, 8:59pm UTC](https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575/2 "2021-02-22T20:59:25Z")

</div>

> [@Giovanni\_Busacca](#):
>
> ```python
> self.buildXY("fire-trap", 30, 45)
> self.buildXY("fire-trap", 30, 31)
> self.buildXY("fire-trap", 30, 16)
> 
> ```

Replace that with:

```python
flagPos = flag.pos
flagX = flagPos.x
flagY = flagPos.y

```

This will define flagX and flagY as the flag’s x and y coordinates.

---

<div class="post-metadata">

**Author:** ![Giovanni\_Busacca](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/giovanni_busacca/32/20806_2.png) [@Giovanni\_Busacca](https://discourse.codecombat.com/u/Giovanni_Busacca)\
**Post date:** [February 22, 2021, 9:03pm UTC](https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575/3 "2021-02-22T21:03:11Z")

</div>

Thank you have a good day!

---

<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:** [February 23, 2021, 9:04am UTC](https://discourse.codecombat.com/t/drop-the-flag-level-help-solved/27575/4 "2021-02-23T09:04:05Z")

</div>

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