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

Long road Python

Hello ,

Why does not this code work?
The hero and the pet walks together. But none of them touches to the red bottles.

Any idea?


item is a variable, not a function. It should be:

if item:


if item():

findNearestItem() is a method that returns something as an object. item is a variable that you are storing that object into. So, let’s pretend that when you findNearestItem(), the nearest item is a health potion. That method will turn the variable (item) into an object (health potion). So when using the object (item), you don’t have to use tuples().


Hello ;

Thanks for your reply. Due to your comment, i changed the code like on the picture.
But actually it still does not work…

Maybe we should use moveXY command with positions of the health potions?

Its really difficult to find enough clues in .

Looking forward for your answers.

That is weird, I would think it should work. Unfortunately it is a subscriber only level, so I can’t test it myself to see what’s going on. What happens when you run the code? Does your pet go and fetch the potions? How are you dying?

Is that your entire code? Because I believe that onSpawn needs to be called at some point (i. e. pet.on("spawn", onSpawn)). Otherwise the function was made for no reason.
Otherwise, you’re good (as far as I can tell).

They walk together until the hero dies.
The pet does not fetch the potions.

Any idea?

After looking some more I just realized that your healthpotion variable is incorrect. you need your pet to find the item, not your hero.

healthpotion = pet.findNearestItem()


healthpotion = hero.findNearestItem()

Also, I believe Hellenar has the right idea. Try putting:


after your onSpawn function if the fix I gave you above does not work.

1 Like