#1

I’ve been stuck on this level for a long time, can someone help me?

#2

Post the code you have so far and we’ll be glad to help. Please be sure to post your code properly using the </> button or post a screen shot so we can see the structure. Thanks.

#3

Here’s my code:

# The function maybeBuildTrap defines TWO parameters!

def maybeBuildTrap(x, y):
# Use x and y as the coordinates to move to.
hero.moveXY(x, y)
enemy = hero.findNearestEnemy()
if enemy:
# Use buildXY to build a “fire-trap” at the given x and y.
hero.buildXY(“fire-trap”, enemy.pos.x, enemy.pos.y)

while True:
# This calls maybeBuildTrap, with the coordinates of the top entrance.
maybeBuildTrap(43, 50)

``````# Now use maybeBuildTrap at the left entrance!
maybeBuildTrap(25, 34)
# Now use maybeBuildTrap at the bottom entrance!
maybeBuildTrap(43, 20)``````

#4

I’ve seen a post about someone with the similar problem before, but I didn’t understand the explanation.

#5

Please learn to post your code properly from the game from now on and use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks. There are many people here willing and able to help. If you use the </> button correctly, then ALL of your code should look like this:

``````while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.say("My code is formatted properly")
``````

If ALL of your code doesn’t look like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you.

#7

It didn’t work for me, sorry.

Nevermind, I’ll look back on the level later on.

#8

It works for everyone. Your account is no different from anyone else’s. Just put all of your code in between the triple back ticks that appear when you click on the </> button.

# ``` <— Triple back tick marks.

Paste ALL of your code in here.

# ``` <— Triple back tick marks.

#10
``````# The function maybeBuildTrap defines TWO parameters!
def maybeBuildTrap(x, y):
# Use x and y as the coordinates to move to.
hero.moveXY(x, y)
enemy = hero.findNearestEnemy()
if enemy:
# Use buildXY to build a "fire-trap" at the given x and y.
hero.buildXY("fire-trap", enemy.pos.x, enemy.pos.y)

while True:
# This calls maybeBuildTrap, with the coordinates of the top entrance.
maybeBuildTrap(43, 50)

# Now use maybeBuildTrap at the left entrance!
maybeBuildTrap(25, 34)
# Now use maybeBuildTrap at the bottom entrance!
maybeBuildTrap(43, 20)

``````

#11

I knew you could figure it out.

In your function, you are telling your hero to build a fire trap at the enemy position. That’s not a good idea because the enemy is moving. You have coordinates in the while True loop that tell you where to put the fire traps. In arguments of your function, all you need to do is put x and y. Then when you call the function, it will use the x and y that you have defined there.

#12

Thanks very much, it was a great help :)

#13

Put [SOLVED] so nobody thinks it isn’t solved.

#14

Ok it’s done now, thanks

#15

Mod edit: Solution removed

#16