Valley of a Thousand Rocks (Python)

It keeps saying that item.pos should be hero.pos but it shouldn’t be.

while True:
    item = hero.findNearestItem()
    if hero.health < hero.maxHealth/3:
        hero.say("Something")
        pass
    if item.pos.x > hero.pos.x:
        hero.moveXY(hero.pos.x+8, hero.pos.y)
        pass
    if item.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y+8)
        pass

Screenshot of Error:

  1. remove the pass, it’s completely redundant/useless
  2. I don’t see anything that might be causing the error

I got rid of the pass but it still won’t work…

do if not item: break before the health check, and do else if for the x and y stuff

@A.Lee452 does it work now

Sry give me a minute

kk

My code now (still doesn’t work):

while True:
    item = hero.findNearestItem()
    if not item:
        break
    if hero.health < hero.maxHealth/3:
        hero.say("Something")
        
    
    if item.pos.x > hero.pos.x:
        hero.moveXY(hero.pos.x+8, hero.pos.y)
        
    else:
        hero.moveXY(hero.pos.x-8, hero.pos.y)
    if item.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y+8)
    else:
        hero.moveXY(hero.pos.x, hero.pos.y-8)
        

no, that’s not what I mean, instead of if, put elif, no else

sorry that I keep @ing you, buttttttttttt, @A.Lee452

I’m at school rn chillll

Code Now(the hero won’t move up only right):

while True:
    item = hero.findNearestItem()
    if not item:
        break
    elif hero.health < hero.maxHealth/3:
        hero.say("Something")
        
    
    elif item.pos.x > hero.pos.x:
        hero.moveXY(hero.pos.x+8, hero.pos.y)
        
    elif item.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y+8)
  1. hero health no elif just if
  2. swap the y and x (as in make it check for y before x)

The hero still won’t move up:

while True:
    item = hero.findNearestItem()
    if not item:
        break
    
    if hero.health < hero.maxHealth/3:
        hero.say("Something")
    
    elif item.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y+8)
    
    elif item.pos.x > hero.pos.x:
        hero.moveXY(hero.pos.x+8, hero.pos.y)
    

@moonwatcher348 helppppppp

get a faster hero? idk, mine works fine with that exact code

I can’t change the hero it’s automatically assigned to me bc I have Hattori but it’s using Anya

you in a class or something?

Yeah I already asked the teacher for help and he doesn’t know

It might be to do with your hero’s vision. There may not be any nearby items in sight when the error occurs, so item is empty (None or null as stated in the error), so I believe that is the source of your error. I may be incorrect, but this is the best guess I have. Real quick, what glasses item do you have equipped?