Mine coding problem on Thunderhooves


#1

Hello I am new to Code Combat, so using python I have some problem with my code it seems it is succeeding but I know its not right.

my code is this

loop:
    yak = self.findNearestEnemy()
    x = self.pos.x        
    y = self.pos.y
    if yak:
        yakPos = yak.pos
        yx = yakPos.x
        yy = yakPos.y                        
        if yy > y:
            y = y + 2          
            self.buildXY("fence", x, y)
    
        else:
            y = y - 2
            self.buildXY("fence", x, y)
    else:
        x = self.pos.x + 10   
        self.moveXY(x, y)

#2

i dont actually see a problem with this.
if you are cunfused with all of these x and yx and so on, you can directly use “self.pos.x” and “yak.pos.y”


#3

The comments clearly state to build 10 meters above/below you. Did you try this?


Despite from that it looks good. You maybe should use more speaking variable-names. You named yakPos in a way I can immediately see what it contains. Why not also yakX and yakY?


#4

you know its really fast for typing and I tried that too also it doesn’t work at 10 or 5


#5

Then it would slowly help to see some screenshots of the situation.


#6

I think the problem is that you have the fence being built where you’re standing. I think you need to move it to where you were just standing, so instead of “self.buildXY(“fence”, x, y)”, try "self.buildXY(“fence”, x + 2, y + 2) and "self.buildXY(“fence”, x - 2, y - 2)