Unable to store positions in variables


#1

Though I have managed to finish Thunderhooves quest in the desert, I thought i would try to tidy up the code a bit, just cause. However, when I try to do the following

while True:
    yak = hero.findNearestEnemy()
    yakPosX = yak.pos.x
    yakPosY = yak.pos.y
    heroPosX = hero.pos.x
    heroPosY = hero.pos.y
    if yak:
        # If yak.pos.y is greater than hero.pos.y
        if yakPosY > heroPosY:
            # buildXY a "fence" 10m below the yak.
            hero.buildXY("fence", yakPosY, yakPosY - 10)
        else:        
            # buildXY a "fence" 10m above the yak.
            hero.buildXY("fence", yakPosX, yakPosY + 10)
    else:
        # moveXY right 10m towards the oasis.
        hero.moveXY(heroPosX + 10, heroPosY)

I get an error at line three, telling me to use hero.pos instead. I don’t follow. Why can’t I store enemy.pos.x in to a variable called enemyPosX…or any variable for that matter. Is it due to item restrictions? Or am I missing something here?

Thanks in advance.


#2

Are you sure that “yak” exists for all frames?


#3

Gah! That’s it. Thanks. It does not…so I am asking it to store a value that technically doesn’t exist yet. Thanks.


#4

what level is this and where


#5

Thunderhooves in the desert


#6

i have done that level i am in the kelvintaph glaciers