[Solved] Stranded in the Dunes possible bug?


#1

i’m having trouble with this level, my hero won’t pick up the flag if my code is this:

# Go to the far right edge of the level to find new areas.
# Check the guide for more details.
while True:
    greenFlag = hero.findFlag("green")
    if greenFlag:
        hero.pickUpFlag(greenFlag)
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "brittleskeleton" :
        hero.attack(enemy)
    if enemy and enemy.type == "brittleskeletonarcher":
        hero.attack(enemy)
    if enemy and enemy.type == "sand-yak":
        hero.say("Stay Away!")
    pass

but he will pick it up if it was like this:

# Go to the far right edge of the level to find new areas.
# Check the guide for more details.
while True:
    greenFlag = hero.findFlag("green")
    if greenFlag:
        hero.pickUpFlag(greenFlag)
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "brittleskeleton" :
        hero.attack(enemy)
    if enemy and enemy.type == "sand-yak":
        hero.say("Stay Away!")
    pass

I Don’t understand why when i add brittle skeleton archer he won’t pick up the flag :confused:


#2

Please learn to post your code properly. It’s really easy and only requires a very small amount of effort.

To post your code from the game, use the </> button or it won’t format properly. When you click the </> button, the following will appear:

Please paste ALL of your code inside the triple back tick marks.

``` <— Triple back tick marks.

Paste ALL of your code in here.

``` <— Triple back tick marks.

There are many people here willing and able to help. If you use the </> button correctly, then ALL of 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 ALL of your code isn’t formatted like the code above, then 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.


#3

Thank you too, I’m still new to this.


#4

You don’t have to name every enemy. You can just say if enemy.type is not equal to sand yak @TheLonelyKing

if enemy.type != "sand-yak":
   hero.attack(enemy)

#5

Thank you, for some weird reason he started picking up the flags


#6

No problem @TheLonelyKing. See you around :smile: