Help with Computer Science 3

Hi, please create a new topic and don’t revive super old ones

I need help with Valley of a Thousand Rockswhile True:

item = hero.findNearestItem()
if hero.health < hero.health / 3:
hero.say(“heal me”)
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)

Correction:
while True:
item = hero.findNearestItem()
if hero.health < hero.health / 3:
hero.say(“heal me”)
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)

hello, welcome :slight_smile:
but please do not revive dead topics, if u need help, just make a new one

And also format your code using the code button please :) you can find everything in the “welcome to discourse” at the top of the page

Hi, @Dhanya_DESAI @Rocco_Nasca , welcome to the codecombat discourse! :smiley: :partying_face:
If you need help click this to create new topic!

(@)Rocco_Nasca posted more than 4 months ago .-.

1 Like
![Screenshot 2022-12-08 9.25.03 PM|674x179](upload://skGgxxul4n1z5eTke3gVUy6Ntup.png)

it keeps saying “cannot read property of ‘pos’ null.”

Screenshot 2022-12-08 9.25.03 PM

What level? :] and can you please post your full code?

The level is the valley of a thousand rocks.

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

Oh interesting I haven’t done this level before, give me a few minutes while I complete it .-.

Well, I actually didn’t have to complete it to see your errors:

if hero.health < hero.health / 3

hero.MAXhealth / 3 (hero.maxHealth / 3)

if item.pos.x > hero.pos.y

hero.XPOSITION (hero.pos.x)

oh also, a good practice is to add spaces after commas

it still does not work

while True:
    item = hero.findNearestItem()
    if hero.maxhealth < hero.maxHealth / 3:
        hero.say("Heal me.")
    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)


if hero.maxHealth < hero.maxHealth / 3

I only mean for you to change the 2nd property, the first should still be normal health

1 Like

Mmm, because its a CS LEVEL

Well, I do have a class account and I’ve never done it, soooo

1 Like

like this?


while True:
    item = hero.findNearestItem()
    if hero.health < hero.maxHealth / 3:
        hero.say("Heal me.")
    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)

it still says the same error
Screenshot 2022-12-15 4.15.21 PM

There might not be an item at that particular moment. You should check if there is one before checking where it is in relation to your hero.

1 Like