Are functors supposed to work?


#1

I’m new to code combat (but not development) and am wondering if the following code should work.

def handleEnemy(enemy):
     #enemy handling code

def patrolTo (start, stop, maxStep, onEnemy):
    loop:    
        e = self.findNearestEnemy()
        if e:
            if not onEnemy(e):
                continue
        # continue patrol

# ...

patrolTo(startPos,stopPos,5,handleEnemy)

My expectation is that handleEnemy should be invoked when an enemy is found, but instead I get the error “object is not a function”.


#2

I also would like to see some real python tag inside the game instead a bunsh of loops , i also suggest to make self.say as print , self.say is more suitable for a game but c’mon we’re here to learn computer language

@Yaur : use the level editor and make a lvl that teach you how to use functions


#3

We’ll be working to improve support and error messages for player-defined functions soon, but it will help if you post your entire code as a GitHub issue so we can try to reproduce: https://github.com/codecombat/codecombat/issues