[SOLVED] Problems with "Passing Through"


#1

My pet wolf isn’t moving at all, so my hero is just standing in place.

Here’s my code if you need it:

while True:
    item = hero.findNearestItem()
    if item:
        # If item.type IS NOT EQUAL TO "gem"
        if item.type != "gem":
            # Then follow your pet wolf.
            hero.moveXY(pet.pos.x and pet.pos.y)
        # Else:
        else:
            if item == ("gem"):
                hero.moveXY(item.pos.x, item.pos.y)

#2

Here is an image of the level and what’s happening (if you guys need it.)


#3

Remove this line line from the else statement:

if item == ("gem"):

It is unnecessary and incorrectly written. I’m no Python expert but from what I’ve seen, this is how you should code it properly:

if item.type == "gem":

#4

Thank you very much!

-Cameron


#5

No problem. Please change the title of this question to [SOLVED] Problems with “Passing Through” so people do not accidentally answer again.


#6

Thing is, I tried this and it didn’t work. What should I do?
Also, when I put and in between “pet.pos.x and y”, it says “You need to put ` in.” What do I do?


#7

If you post your code it would be a lot easier to see what the issue is. Why are you putting ‘and’ in between pet.pos.x, pet.pos.y? ‘And’ shouldn’t be there. There should just be a comma separating the two.

If you have questions about how to format a method, just click on the method in question in the middle portion of the screen. It will give you the proper format. When you click on the moveXY(x, y) method you can see that there is no ‘and’ in the parenthesis.


#8

Thanks
I didn’t know. I looked at the picture and saw the word "AND"
I wasnt sure what to do.