Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] Please help with Usual day (backwoods forest). I would really appreciate it. I don't know what to do after the line "if item and item.type == "coin":

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.
    # Collect item if it exists and its type is "coin".
    item = hero.findNearestItem()
    if item and item.type == "coin":
        

1 Like

Can you give the link please?

What do you mean?
ignore this
Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

the link of the level

(https://codecombat.com/play/level/usual-day?)

You defined the item but you didn’t move to it.

yeah so like it says hero.attack(enemy), what am supposed to say in terms of collecting the coin? Meaning, how do you collect it ? do you say

 items = hero.findItems()

hero.moveXY(item.pos.x, item.pos.y)

yeah but when i put that it says incomplete, it says that i did more then 8 statements

items = hero.findItems()`would make a array`

Did you write items = hero.findItems()?
because if you did delete it.

when i delete that it says item is not defined

Can you show me your code right now?

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

item = hero.findItems should be `item = hero.findNearestItem`

except for that your code looks right

ok i tried it and here is what happened:
image

I found your problem you didn’t add () on the end of item = hero.findNearestItem()
sorry I did that

THank you it worked!

Glad it did :grin:
(20 chars)