Long road Python


#1

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?

Thanks.
Murat


[Solved] Why I cannot pass "LONG ROAD" with hints?
#2

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

if item:

not

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().


#3

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 codecombat.com .

Looking forward for your answers.


#4

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?


#5

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).


#6

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

Any idea?


#7

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()

not

healthpotion = hero.findNearestItem()

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

pet.on("spawn",onSpawn)

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


Long Road Please Help Me Solve This!