Help on Peek-A-Boom

Hey dudes, I was having a little trouble on Pee A Boom. It said I needed to pair the else statement with the if statement, I did that, and it is still saying the same thing. Help would be appreciated anyone can help but help would especially be appreciated from @nick. Thanks!

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.buildXY("fire-trap", 41, 24)
        hero.moveXY(15, 16)
        pass
while True:
        
    else:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.buildXY("fence", 41, 24)
            hero.moveXY(15, 16)
3 Likes

Never heard of a level called “Pee” a Boom :laughing:. Jokes aside, you do not need 2 While True loops in this level. Get rid of the second while true loop. It separates the if and else, so the system bugs out, trying to look for the if of the else.

4 Likes

I did that and now it completes the commands the first time but will not execute them continually.

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.buildXY("fire-trap", 41, 24)
        hero.moveXY(15, 16)
        pass


    else:
        enemy = hero.findNearestEnemy()
        if enemy:
            hero.buildXY("fence", 41, 24)
            hero.moveXY(15, 16)
3 Likes

No. Instead of building a fence, you just move back to wooden X. No need to find nearest enemy again. That was the purpose of the first if statement.

4 Likes

Now it says the else must be paired with the ``if```` again

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # <%= build_fire-trap %>
        hero.buildXY("fire-trap", 36, 30)
        hero.moveXY(19, 19)
        pass

    else:
        hero.buildXY("fire-trap," 36, 30)
        hero.moveXY(19, 19)
2 Likes

I don’t think you need that second hero.buildXY("fire-trap", 36, 30)

4 Likes

Try three things. Eliminate the one line of space between the pass command and the else statement. Also, get rid of the buildXY in the else statement. Now, change the build fire trap location in the if statement to build on the red X.

4 Likes

He already has that in his code, so there’s no issue there.

3 Likes

look at this bug

3 Likes

What is if else:?
You do not need to set up a separate while-true loop. Just include an else-statement in the first one.
No need to use a fence either :slight_smile:

2 Likes

im stuck becasue like i tried all of these no did not work someone gets blown up!!!

Please post your code and give any other additional information that would be helpful

I did this and it works try it

(Solution removed)

Please don’t post solutions. The purpose of this board is to help people learn so that they can figure out levels on their own. Simply providing solutions does not help and is counterproductive to this goal. The two main rules here on this board are no swearing and no posting solutions. Thanks and welcome to the board.

2 Likes

i wanna try with Shield option on 19, 19 but couldn’t figure out how to bypass peasants only. any suggestions ? please!

Use findFriends() to find friends (including peasants) that you can see. It works totally like findEnemies(), but it finds your allies.

1 Like

& then how to block gateway only for enemy?

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