Underground Business

What is wrong with my code, I’ve spent way too much time on something that seems like a bug, and not actually code related. The coins get collected, the collector shows 300+, and the guy won’t leave the cave.

def onSpawn(event):
    # Send the pet to walk around the dungeon:
    pet.moveXY(69, 57)
    pet.moveXY(71, 57)
    pet.moveXY(71, 11)
    pet.moveXY(20, 11)
    pet.moveXY(21, 36)
    pet.moveXY(15, 36)
    pet.moveXY(hero.pos.x, hero.pos.y)
    # Don't forget to return it to the hero:

pet.on("spawn", onSpawn)

while True:
    # Guard peasants:
    enemy = hero.findNearestEnemy()
    # When you have 300+ gold move to the red mark:
    if enemy:
        hero.moveXY(21, 34)
    if hero.gold>=300:
        hero.moveXY(50, 34)

I keep having these problems with CodeCombat, I’ve experience multiple levels where it doesn’t work as intended. At this point it feels like I’m spending more time troubleshooting the platform, not evaluating my code. If this doesn’t stop happening, I’m going to cancel my subscription and find a different way to learn. This just isn’t a good use of time if I keep having to dig through old articles trying to figure out bugs.


you forgot a step, it says move to the the red x when you get 300 + gold

you need to put the exit line in front like this, otherwise the hero will try and execute the attack the enemy or do the wrong moveXY because they are in front

if hero.gold>=300:
    hero.moveXY(50, 34)
elif enemy:
    hero.moveXY(21, 34)

Besides the fact my code says to go to the red x in the last line - I’ve tried 50 different combinations of code to make him move, and none of them have worked. Multiple ifs, elif, breaks, etc.
At this point, I just cheated and used the flag method, because nothing worked.

Already tried that, it didn’t work

You might need an upgraded amulet. Don’t think the one you are using now can use hero.gold

That was the problem. Why would this level not require that item to be equipped if the stupid level won’t work without it. I wasted an hour because of that.
Thanks, Luke.

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