Type Error Issues

Often when I an playing a level, I get a type error.
Ex.
while True:
item = hero.findNearestItem()
if item:
continue
elif item.type == “poisen”:
continue

error will happen on the elif line.
Any explanations?

Provide a complete code and the level

Now it looks like

if item exist start loop over
if item not exist and type of not existing item = poison
start loop over

it is make no sense for me

1 Like

Its multiple levels, but ill get a specific one

while True:
item = hero.findNearestItem()
enemy = hero.findNearestEnemy
hero.say(“Potion”)
if not enemy:
continue
elif item:
continue
elif item.type == “poisen”:
continue
hero.moveXY(44, 35)
hero.moveXY(34, 47)
continue

you can guess where the indentations are

Regarding errors

add () at the end of

enemy = hero.findNearestEnemy

Add check for existence of item
you can not read the type of non-existent item

if item:

or

elif item and item.type == "poisen"

change “poisen” to “poison”

Regarding logic its too weak
for example
if not enemy and not item hero will move to hero.moveXY(44, 35)
if enemy and item hero will stay still.

Try to alter
or use a simple and reliable
if
if
if

1 Like

I was just using the base code. It is there bc it is supposed to work, but i guess not

as @htrnblr mentioned

I would recommend checking for the existence of items, enemies, friends, etc. If the code runs before these objects exist in the game, or if the objects you are looking for are too far away or blocked from vision the value stored will be null or undefined.

Trying to access a null variable’s attribute will case an error.

1 Like

It is bc i spelled “poison” wrong
Thx tho