Python: while loop does not work on another level

Hello codePros,

I am not sure why the same logic does not work on one level that worked before on a previous one. The code that worked:

while-loop with increment

The code that did not work on level mirage maker:

# Lure the ogres into an ambush!

# While your gold is less than 25, collect coins. = 0
while < 25:
    item = hero.findNearestItem()
    if item:
        hero.moveXY(item.pos.x, item.pos.y) += 1
# After the while loop, build a "decoy" at the white X.
hero.buildXY("decoy", 72, 68)
# While your health equals maxHealth, say insults
while == hero.maxHealth:
    hero.say("Your mom slept with lizards.")
    hero.say("That stone next to you is more clever than you")
    hero.say("A bug can bug me more than you")

# Then move back to the red X.
hero.moveXY(22, 16)


I tried to use the same logic and I am not sure what went wrong. The FAQ of this forum does not mention anything about protected property and google failed me on this one. Any idea?

Try to change to any other variable, like Total Gold f.e.

1 Like

it should be according to the game:

However I tried your suggestion and that error says “total not defined”.
It really worked in every previous case I can recall.

Try doing:

total =

or something like that?

You may not have an item that can do .gold
If you’re not sure, you can send a screenshot of your armor.

Mhm. I think you need quartz sense stone and above?


Oh, I see. So I guess @CocoCharlie and @thebagel may be right.

In game documentation example you may “look” how much gold does your hero have. Your code += 1 tries to change amount. It’s like*100 it won’t work, protected property alert displays in this case.
Again, looks like you need special item and total = variable.

1 Like

Yup, it’s quartz sense stone or above. Just checked.


Or simply delete the lines изображение and изображение
and the working code will be
but there is something your mother will not like :slight_smile: :
It’s better simply to stay still until the ogres approach and then run ( sorry, javascript, but the idea is clear)

hero.buildXY("decoy", 72, 70);
// While your health equals maxHealth, say insults No, No, No - I'm a good boy/girl!
while (true){
    var enemy = hero.findNearestEnemy();
    // if ( == hero.maxHealth) is the way the help tells you but is little bit dangerous
    if ( hero.distanceTo(enemy) > 10)
       hero.moveXY(hero.pos.x, hero.pos.y);
     else break;

@xython : this is indeed what worked.

To have the full picture: I had the quartz stone but bought one the next level of necklace also to see whether it’s just a game bug but got the same error. When I removed those two values, it worked like a charm.
@Alexbrand , you made me think about what you wrote, that explains at least half of the problem, thank you for the idea.

TL,DR: All in all, thank you for all the support, I can move forward for a better understanding how coding works!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.