Type Error Issues


#1

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?


#2

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


#3

Its multiple levels, but ill get a specific one


#4

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


#5

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


#6

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


#7

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.


#8

It is bc i spelled “poison” wrong
Thx tho