Black Diamond <-- Help Needed


#1

All my guy does is move to the first couple of gems and then stop. I can’t figure out why he’s not returning to the middle.

while True:
    gem = hero.findNearest(hero.findItems())
    whiteX = {"x": 40, "y": 35}
    if gem:
        clear = hero.isPathClear(hero.pos, gem.pos)
        # The isPathClear method tells you if there’s an obstacle in the way.
        # If it’s clear, move() to gem.pos.
        if clear:
            hero.move(gem.pos)
            # Else, move back to the center point.
        elif hero.isPathClear(hero.pos, whiteX):
            hero.move(whiteX)

Hangs on elif statement.


#2

Try switching your elif to an else statement, that way you have an if and a else, and throw a if statement to check if path is clear to white x inside of that else statement.


#3

I agree that those are good ideas but I’ve already tried them. Whenever I change the elif statement to else, it gives a red error telling me that the else statement needs to be indented correctly with the if statement. It gives this error no matter where the else statement is indented to. :confused:


#4

In this level you don’t need to check if the path to the center point is clear. Just do an else: instead of the elif:.


#5

Sadly. Not sure what to do then.


#6

What gear are you using? I switch your elif to and else: and it works fine.


#7

Using compound boots with move or moveXY available.


#8

Send an email to team@codecombat.com please, lemme look.


#9

I’m home and on a different machine now and just followed your suggestion. It’s no longer giving me the indentation error when I change to else instead of elif. I’m not sure what was going on there.

After getting rid of the if statement it’s working. Thank you.