Munchkin Swarm Python: Unexpected tokens and a random encounter with .pos


#1

Hi folks. I started playing CodeCombat months ago, was addicted for a week or two, then quit playing entirely after getting stuck on this level.

I’ve now come back to try it again, and figured I’d test the code given in the help video (I’ve lost my original solution with all the edits).

Well, that solution doesn’t work either, and the video refers to “.pos, which was covered in the last level”. .pos is not covered in the last level, and I had never seen it before.

In addition, I keep getting “unexpected token” errors, even when I try to run the sample code that works!

Not sure what to do.

Here’s the code I’m using:

loop:
    enemy = self.findNearestEnemy()
    enemyDistance = self.distanceTo (enemy.pos)
    if self.isReady("cleave"):
        if enemyDistance = < 10m:
            self.cleave(enemy)
        else:
            self.attack("Chest")
    else:
        self.attack("Chest")

Thanks for any help you can offer.


#2

Here’s what I did: I got a powerful weapon and strong armour and just kept attacking the chest. See if that works.


#3

In the future, read the FAQ before you post, and learn how to properly format your code. I’ve done it for you this time.

Your if-statement to check the distance is wrong. The proper notation for “less than or equal to” is <=, not = <. Also, where did the m come from? That is completely unnecessary, and would cause the unexpected token error.


#4

You just beat me to it, Chronist! :slight_smile:
Yeah, the program thinks you’re saying:

if enemyDistance (assign variable) < 10m:
    etc