[SOLVED] Hero Dies in Usual Day (Python)

New here. I’m trying to play Usual Day and for some reason, towards the end of the level, a mushroom appears and an enemy appears right in line with the mushroom. The hero goes towards the enemy, getting the mushroom on the way and dies.

Defeat munchkins, collect coins. Everything as usual.

Use AND to check existence and type in one statement.

while True:
enemy = hero.findNearestEnemy()
# With AND, the type is only checked if enemy exists.
if enemy and enemy.type == “munchkin”:
hero.attack(enemy);
# Find the nearest item.
item = hero.findNearestItem()
# Collect item if it exists and its type is “coin”.
if item and item.type == “coin”:
hero.moveXY (item.pos.x, item.pos.y);

I can have the hero move to another spot to avoid the mushroom but that’s eight lines of code and won’t complete the level.

2 Likes
while True:
enemy = hero.findNearestEnemy()
# With AND, the type is only checked if enemy exists.
if enemy and enemy.type == "munchkin":
hero.attack(enemy);
# Find the nearest item.
item = hero.findNearestItem()
# Collect item if it exists and its type is "coin".
if item and item.type == "coin":
hero.moveXY (item.pos.x, item.pos.y);

No that is only 7 lines, so you should be able to complete the level. Also, make sure you format the code by wrapping it with three ticks. The result is easier to read.

1 Like
while True:
    enemy = hero.findNearestEnemy()
    # With AND, the type is only checked if enemy exists.
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy);
    # Find the nearest item.
    item = hero.findNearestItem()
    # Collect item if it exists and its type is "coin".
    if item and item.type == "coin":
        hero.moveXY (item.pos.x, item.pos.y);

That’s better. It wants you to do it with under eight lines of code and that’s the seven lines. I’ll try with a different hero and see what happens.

3 Likes

Sure, try it with another hero. I tried that exact same code and it worked for me. I counted, only 7 lines, so it should fall into the under 8 category.

2 Likes

Well. it works now. I logged off, logged back in and played it. I guess it’s just the way the objects were being spawned on that first round. It just so happened a poisonous mushroom was in the way of getting to an enemy. Thanks!

3 Likes

I think the mushroom is there on purpose. And there is a trick to avoid it!

In the last line, don’t go exactly to the item, you can pick it up even if you go to

hero.moveXY (item.pos.x-1, item.pos.y-1);

This way the distance to mushroom is long enough to avoid it :slight_smile:

Or submit for a different seed. Also, please do not revive dead threads :slight_smile:

but the hero goes to defeat a munchkin getting poisoned on the way

Hi, do you need help with this level? If so please post your code formatted, with three ``` at the start and end of your code on a new lines.
Danny

help me im sort of stuck

while True:
    enemy = hero.findNearestEnemy()
    pass
# With AND, the type is only checked if enemy exists.
if enemy and enemy.type == "munchkin":
    hero.attack(enemy);
    pass
# Find the nearest item.
item = hero.findNearestItem()
# Collect item if it exists and its type is "coin".
if item and item.type == "coin":
    hero.moveXY (item.pos.x, item.pos.y);
    pass

my code isnt working as i would like it is just finding the enemy and not attacking it, nor moving at all

Hello! I think your code isn’t working, because it isn’t in While True.
Everything (item, if’s moveXY) should be in the While True loop. Not only enemy.

2 Likes

Like @PeterPalov said, you need to put all of this into the while true loop.

help me i still cant do it, im not sure what to do

Please could you post your new code.