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:
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.
hero.gold = 0
while hero.gold < 25:
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x, item.pos.y)
hero.gold += 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.health == 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?
In game documentation example you may βlookβ how much gold does your hero have. Your code hero.gold += 1 tries to change hero.gold amount. Itβs like hero.health=hero.health*100 it wonβt work, protected property alert displays in this case.
Again, looks like you need special item and total = hero.gold variable.
Or simply delete the lines and
and the working code will be
but there is something your mother will not like :
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.health == 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;
}
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!