I have been stuck on this level for a while can you please help me with my code this is it
You didn’t define any distance
variable or any of the variables. You have to define all of them in order for them to work
This is my new code I tried.
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
if self.distanceTo(coin) < 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:
self.moveXY(nearest.pos.x, nearest.pos.y)
i will summon you
I can’t really see the code unless you preformat the text using three back ticks [```]
Be sure to copy your code from the game and use the </> button or it won’t format properly. There are many people here willing and able to help. If you use the </> button correctly, your code should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.say("My code is formatted properly")
If it doesn’t look like the code above, you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you and welcome to the board.
</> 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
if self.distanceTo(coin) < 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:
self.moveXY(nearest.pos.x, nearest.pos.y)
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
if self.distanceTo(coin) < 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:
self.moveXY(nearest.pos.x, nearest.pos.y)
Is that good?
Please reply as soon as possible i’m coding right now.
@Chaboi_3000 SUMMONED
I think that’s good to me, though. Does it work?
No, my character just runs into the mine. I think there is a bug because my character stops in place then goes into the mine.
I just used the flags and won.
I’m trying to pass the level how it’s used. If you want you can use flags. ;-;
I still beat it without flags.