Unable to store positions in variables

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)
            # buildXY a "fence" 10m above the yak.
            hero.buildXY("fence", yakPosX, yakPosY + 10)
        # 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.

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

1 Like

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

1 Like

what level is this and where

Thunderhooves in the desert

i have done that level i am in the kelvintaph glaciers