# Problem with Sand Snakes

So, I have this problem where my hero cannot move. This is because the computer can recognise “nearest.pos” but when I tag on “.x”, making “nearest.pos.x” it falls apart. Any help would be greatly appreciated!
Code:

``````# This field is covered in firetraps.  Thankfully we've sent a scout ahead to find a path.  He left coins along the path so that if we always stick to the nearest coin, we'll avoid the traps.

# This canyon seems to interfere with your findNearest glasses!
# You'll need to find the nearest coins on your own.

loop:
coins = self.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999

# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
distance = self.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if self.distanceTo(coin) < nearestDistance:
# Set nearest to coin
nearest = coins
# Set nearestDistance to distance
nearestDistance = distance

# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if nearest:
self.moveXY(nearest.pos.x, nearest.pos.y)
``````

Screenshot of error message:

You have a typo:

``````nearest = coins
``````

Should be:

``````nearest = coin
``````
2 Likes

Thank you so much! It worked.

No problem.

The error message is a bit odd though, it should say “nearest.pos is undefined” instead of showing the transpiled code’s variable names. @nick Is this a limitation or a bug in Aether?

It’s a limitation that we should be able to work around, but it may take some doing. I think we need to just keep track of the error range and the original code range and replace the error message about the tmp variables to use the original string of code.

hi Been reading comments can’t figure out a solution to my problem

‘’’

# You’ll need to find the nearest coins on your own.

while True:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
if coin:
distance = hero.distanceTo(coin)
# If this coin’s distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there’s a nearest coin, move to its position. You’ll need moveXY so you don’t cut corners and hit a trap.
if nearest:
hero.moveXY(nearest.pos.x, nearest.pos.y)
‘’’
also this game should be called code quest it sounds better
I am using a Mac and can’t find the key sry

I have fixed it now no need to worry

1 Like