Crux of desert: What is wrong with my code?


#1

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)

#2

@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?


#3

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


#4

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


#5

This post is 8 months old. DO NOT REPLY!


#6

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