Question about Marauder in Sarven Desert


#1

I’ve completed this level - kind of. It works and says successful, however I don’t understand what the line,

# Reassign the coin variable to the nearest item

is supposed to do. This is blank in my code and it runs fine.

`while True:
    coin = hero.findNearest(hero.findItems())
    # While a coin exists:
    if coin:
        # Move to the coin.
        hero.moveXY(coin.pos.x, coin.pos.y)
        # Reassign the coin variable to the nearest item.
        (Yellow arrow pointing at this line)
    `

There is still a yellow arrow pointing at this line indicating that I need to write something there but it seems to run fine without it.

Please explain how that is supposed to work. Obviously I’m missing something.

Thank you.


#2

@MunkeyShynes I’ve come across that quite often. I’ve realized it is just trying to say that the code should be written there referring to what explanation it is giving. You can write the entire code somewhere else and so long as the code is correct and works in the way it is supposed to you will still pass the level but the arrow may remain there thinking that you haven’t done that step yet. I usually just get rid of said line if I come across this issue, but perhaps someone more experienced knows a better answer than I. Still hope it helps. :slight_smile:


#3

@MunkeyShynes as @Xector64 was saying it won’t affect your code.

The game is setup in a way that it asks you to place code pieces in certain locations. In your case you have the code it was asking for before the if statement. If your way works as well, then you are fine. There are more then one solution to each problem. But the system isn’t necessarily able to check all of these combinations yet to know that you are ok.

There are cues in the source to tell the game to place a yellow arrow after such a comment to help the students that may not know what to do next.

Does that make sense?

-HW


#4

My code seemed long, but it worked:

[removed correct solution]


#5

My code has a strange problem. My code should run correctly, but for some reason, I only collect the first two coins and then stop. My code doesn’t have any errors that I can see.

Destroy mechs and collect gold from them.

coinIndex = 0
while True:
coin = hero.findNearestItem()
# While a coin exists:
while coin:
# Move to the coin.
hero.moveXY(coin.pos.x, coin.pos.y)
# Reassign the coin variable to the nearest item.
coinIndex += 1
enemy = hero.findNearestEnemy()
if enemy:
# While enemy’s health is greater than 0.
while enemy.health > 0:
# Attack enemy.
hero.attack(enemy)
pass


#6

Please format your code according to the FAQ.


#7

I’m not sure if that’s a real command at all


#8

Thanks. I found the problem. I said while instead of if.