Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Type Error Issues


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

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


Its multiple levels, but ill get a specific one


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

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:


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


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.


It is bc i spelled “poison” wrong
Thx tho