Crux of desert: What is wrong with my code?

I don’t know why it did not work on this one.
while True:
enemy = hero.findNearestEnemy()
if enemy:
isLeft = hero.pos.x > enemy.pos.x
isAbove = hero.pos.y < enemy.pos.y
isRight = hero.pos.x < enemy.pos.x
isBelow = hero.pos.y > enemy.pos.y
if isLeft and isAbove:
hero.buildXY(“fire-trap”, 40 - 20, 34 + 17)

if isRight and isAbove:
    hero.buildXY("fire-trap", 40 + 20, 34 + 17)
    
if isLeft and isBelow:
    hero.buildXY("fire-trap", 40 - 20, 34 - 17)
    
if isRight and isBelow:
    hero.buildXY("fire-trap", 40 + 20, 34 - 17)
    
else:
    hero.moveXY(40, 34)
    hero.wait(0.2)
1 Like

@Jiayao_Wang can you repost the code using the block quote button so that I can ensure you have all the correct tabs?

Also what doesn’t the code do?

1 Like

if isRight and isAbove:
hero.buildXY(“fire-trap”, 40 + 20, 34 + 17)

if isLeft and isBelow:
hero.buildXY(“fire-trap”, 40 - 20, 34 - 17)

if isRight and isBelow:
hero.buildXY(“fire-trap”, 40 + 20, 34 - 17)

else:
hero.moveXY(40, 34)
hero.wait(0.2)Preformatted text

1 Like

while True:
enemy = hero.findNearestEnemy()
if enemy:
isLeft = hero.pos.x > enemy.pos.x
isAbove = hero.pos.y < enemy.pos.y
isRight = hero.pos.x < enemy.pos.x
isBelow = hero.pos.y > enemy.pos.y
if isLeft and isAbove:
hero.buildXY(“fire-trap”, 40 - 20, 34 + 17)Preformatted text

1 Like

This post is 8 months old. DO NOT REPLY!

2 Likes

Yes!!! Please read the FAQ before posting. Topics like this that has been left alone should not be brought back up!!!

1 Like