Crux of the Desert(python)

It’s saying “isLeft” is not defined

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # Left: enemy.pos.x is less than hero.pos.x
        isLeft = enemy.pos.x < hero.pos.x
        # Above: enemy.pos.y is greater than hero.pos.y
        isAbove = enemy.pos.y > hero.pos.y
        # Right: enemy.pos.x is greater than hero.pos.x
        isRight = enemy.pos.x > hero.pos.x
        # Below: enemy.pos.y is less than hero.pos.y
        isBelow = enemy.pos.y < hero.pos.y
        # If enemy isAbove and isLeft:
        # buildXY() a "fire-trap" at the X mark.
        if isLeft and isAbove:
            hero.buildXY("fire-trap", 20, 51)
            # If enemy isAbove and isRight:
            # buildXY() a "fire-trap" at the X mark.
        if isAbove and isRight:
            
            hero.buildXY("fire-trap", 60, 51)
        # If enemy isBelow and isLeft:
        # buildXY() a "fire-trap" at the X mark.
        if isBelow and IsLeft:
            hero.buildXY("fire-trap", 20, 17)
        # If enemy isBelow and isRight:
        # buildXY() a "fire-trap" at the X mark.
        if isBelow and isRight:
            hero.buildXY("fire-trap", 60, 17)
        hero.moveXY(40, 34)
    else:
        hero.moveXY(40, 34)

Hey @CocoCharlie, the issue with your code is this:

Small mistake, but you capitalized the I and when you defined isLeft, the I is lowercase. Besides that I think your code is fine!

Grzmot

Thank you that worked!

1 Like

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