# \[SOLVED\] Help with Decoy Drill

**URL:** <https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561>\
**Category:** Level Help\
**Created:** [May 13, 2020, 7:25pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561 "2020-05-13T19:25:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 13, 2020, 7:25pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/1 "2020-05-13T19:25:54Z")

</div>

```python
decoysBuilt = 0
while True:
    coin = hero.findNearestItem()
    
    if coin:
        # Collect the coin!
        hero.moveXY(coin.pos.x, coin.pos.y);
        pass
    # Each decoy costs 25 gold.
    # If hero.gold is greater than or equal to 25:
    if hero.gold >= 25:
        # buildXY a "decoy"
        hero.buildXY("decoy", 36, 30)
        # Add 1 to the decoysBuilt count.
        decoysBuilt == decoysBuilt + 1
        if decoysBuilt == 4:
            # Break out of the loop when you have built 4.
            break
            pass
            
hero.say("Done building decoys!")
hero.moveXY(14, 36)
# Say how many decoys you built.
hero.say("I built 4 decoys")

```

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 13, 2020, 7:26pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/2 "2020-05-13T19:26:40Z")

</div>

it keeps making more than 4 decoys and I cannot figure out how to stop it from doing so. Please help!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 13, 2020, 10:00pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/3 "2020-05-13T22:00:24Z")

</div>

Dan, you defined the variable decoyBuilt for a reason. In your final statement, you are having your hero say a literal string…instead, have him say the concatenation of the variable + the words to say.

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 14, 2020, 4:04pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/4 "2020-05-14T16:04:54Z")

</div>

so I should have him say “hero.say(DecoysBuilt)”  
instead of my origanal statement?

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 14, 2020, 5:57pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/5 "2020-05-14T17:57:56Z")

</div>

```python
decoysBuilt = 0
while True:
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y);
        pass
    if hero.gold >= 25:
        hero.buildXY("decoy", 36, 30)
        decoysBuilt == decoysBuilt + 1
        if decoysBuilt == 4:
            break
            pass
            
            hero.say("Done building decoys!")
            hero.moveXY(14, 36)
            hero.say("I built 4 decoys")

```

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 14, 2020, 5:59pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/6 "2020-05-14T17:59:16Z")

</div>

I modified the code but it is not registering the if “decoysBuilt == 4: statement”.  
Please help!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 14, 2020, 6:09pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/7 "2020-05-14T18:09:10Z")

</div>

Actually, the original code was good, just one line needed to be changed, and yes, have him say that…only, be careful of spelling and capitalization…they count!

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 14, 2020, 6:13pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/8 "2020-05-14T18:13:18Z")

</div>

The new version you posted has the final statements indented so that they are now part of the preceding if block…you don’t want to indent them.

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 14, 2020, 6:56pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/9 "2020-05-14T18:56:39Z")

</div>

can you send me a completed code to compare with because I really need to see what is going on cause I think I fixed all of it but it still builds more than 4 decoys

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 14, 2020, 7:03pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/10 "2020-05-14T19:03:23Z")

</div>

Sorry, no can do. Instead, copy the code from your first post in to the game editor, replacing what you now have. Then, edit the ‘say’ statement:

```python
# Say how many decoys you built.
hero.say("I built 4 decoys")

```

To match what you asked in the 4th reply on this topic…simple 🙂

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 15, 2020, 5:31pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/11 "2020-05-15T17:31:18Z")

</div>

should this code work?

```python
decoysBuilt = 0
while True:
    coin = hero.findNearestItem()
    if coin:
        hero.moveXY(coin.pos.x, coin.pos.y);
    if hero.gold >= 25:
        hero.buildXY("decoy", 36, 30)
        decoysBuilt = decoysBuilt + 1
        hero.say("hi" + hero.gold)
        hero.say("hello" + decoysBuilt)
        
    if decoysBuilt == 4:
        hero.moveXY(14, 36)
        hero.say("I built 4 decoys")

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 15, 2020, 5:55pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/12 "2020-05-15T17:55:25Z")

</div>

No…start over with the code from your original post:

```python
decoysBuilt = 0
while True:
    coin = hero.findNearestItem()
    
    if coin:
        # Collect the coin!
        hero.moveXY(coin.pos.x, coin.pos.y);
        pass
    # Each decoy costs 25 gold.
    # If hero.gold is greater than or equal to 25:
    if hero.gold >= 25:
        # buildXY a "decoy"
        hero.buildXY("decoy", 36, 30)
        # Add 1 to the decoysBuilt count.
        decoysBuilt == decoysBuilt + 1
        if decoysBuilt == 4:
            # Break out of the loop when you have built 4.
            break
            pass
            
hero.say("Done building decoys!")
hero.moveXY(14, 36)
# Say how many decoys you built.
hero.say("I built 4 decoys") # and simply change this line

```

> [@DanTDM\_4](#):
>
> so I should have him say “hero.say(DecoysBuilt)”

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 15, 2020, 6:07pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/13 "2020-05-15T18:07:05Z")

</div>

nope it works. I just tested it

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 15, 2020, 6:07pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/14 "2020-05-15T18:07:26Z")

</div>

try it on your code stuff and see if that works

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [May 15, 2020, 6:15pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/15 "2020-05-15T18:15:21Z")

</div>

lol…I didn’t realize the question there, was still focused on your original. But yes, it works.

---

<div class="post-metadata">

**Author:** ![DanTDM\_4](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dantdm_4/32/13224_2.png) [@DanTDM\_4](https://discourse.codecombat.com/u/DanTDM_4)\
**Post date:** [May 15, 2020, 6:16pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/16 "2020-05-15T18:16:50Z")

</div>

Yay, glad that it works for more than 1 person!

---

<div class="post-metadata">

**Author:** ![Rachel699](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rachel699/32/13569_2.png) [@Rachel699](https://discourse.codecombat.com/u/Rachel699)\
**Post date:** [July 4, 2020, 2:57pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/17 "2020-07-04T14:57:41Z")

</div>

It doesn’t work for me…  
Code:

```python
decoysBuilt = 0
while True:
    coin = hero.findNearestItem()
    
    if coin:
        # Collect the coin!
        hero.moveXY(coin.pos.x, coin.pos.y);
        pass
    # Each decoy costs 25 gold.
    # If hero.gold is greater than or equal to 25:
    if hero.gold >= 25:
        # buildXY a "decoy"
        hero.buildXY("decoy", 36, 30)
        # Add 1 to the decoysBuilt count.
        decoysBuilt == decoysBuilt + 1
        if decoysBuilt == 4:
            # Break out of the loop when you have built 4.
            break
            pass
            
hero.say("Done building decoys!")
hero.moveXY(14, 36)
# Say how many decoys you built.
hero.say("I built 4 decoys") # and simply change this line

```

---

<div class="post-metadata">

**Author:** ![dedreous](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/dedreous/32/13849_2.png) [@dedreous](https://discourse.codecombat.com/u/dedreous)\
**Post date:** [July 4, 2020, 3:07pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/18 "2020-07-04T15:07:10Z")

</div>

There should be only one equal sign in decoysBuilt.

---

<div class="post-metadata">

**Author:** ![Rachel699](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/rachel699/32/13569_2.png) [@Rachel699](https://discourse.codecombat.com/u/Rachel699)\
**Post date:** [July 4, 2020, 3:19pm UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/19 "2020-07-04T15:19:59Z")

</div>

Oh. Okay! Thanks for the help! I passed the level!

---

<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:** [July 5, 2020, 3:20am UTC](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561/20 "2020-07-05T03:20:01Z")

</div>

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

[Next page](https://discourse.codecombat.com/t/solved-help-with-decoy-drill/21561.md?page=2)
