My code says the item is undefined


#1

I’m not sure why, but the coding i have is saying that item is undefined in line 12. Can anyone plz help?


#2

What level? Can you post your code? A screen shot? There are many line 12’s throughout Code Combat.


#3

my bad Usual Day is the level im stuck on


#4

Can you post your code? Either use the </> button or a screen shot would be great. Then we can see line 12 and identify the problem. It’s really difficult to assist with a code problem when I have no idea what your code is. Thanks.


#5

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.
items = hero.findNearestItem()
# Collect item if it exists and its type is “coin”.
if item and item.type == “coin”: (reference error: item is not defined)
hero.moveXY(item.pos.x-1, item.pos.y-1)


#6

The error is correct. You have not defined item. You have defined items.


#7

ok so what am I supposed to do cause i looked up some help and it told me to do exactly that.


#8

ok nevermind thanks for the help!!!