Usual day help shorting the code to lower than 8 lines

could you help me on the level usual day in the backwoods forest? this was the code could you shorten it?

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        pos = item.pos
        x=pos.x
        y=pos.y
        hero.moveXY(x, y)

Hi!
You don’t need to define item.pos, pos.x and pos.y . These three lines are unnecessary )
Good luck!

1 Like

but if I try It will not work

You can use the item.pos.x and item.pos.y directly in the moveXY function.

but I have 9 statements instead of 8

while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        x=item.pos
        y=item.pos
        hero.moveXY(item.pos.x, item.pos.y)
while True:
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type == "munchkin":
        hero.attack(enemy)
    item = hero.findNearestItem()
    if item and item.type == "coin":
        x=item.pos
        y=item.pos
        hero.moveXY(item.pos.x, item.pos.y)

This code is correct, just put out lines defining “x” and “y”.

P.S. It’s possible to make this lvl with 6 lines ) (at least with Pyton, idk about other languages)

thank you very much, It worked!

1 Like