Sarven Treasure/ python/ help

I don’t know what to do. It can’t find GoldCoin.pos.x

while True:
    enemy = hero.findNearestEnemy()
    coin = hero.findItems()
    GoldCoin = coin.value = 3
    SilverCoin = coin.value = 2
    CopperCoin = coin.value = 1
    if GoldCoin:
        GoldCoinX = GoldCoin.pos.x
        GoldCoinY = GoldCoin.pos.y
        hero.moveXY(GoldCoinX, GoldCoinY)
    elif SilverCoin:
        SilverCoinX = SilverCoin.pos.x
        SilverCoinY = SilverCoin.pos.y
        hero.moveXY(SilverCoinX, SilverCoinY)
    elif CopperCoin:
        CopperCoinX = CopperCoin.pos.x
        CopperCoinY = CopperCoin.pos.y
        hero.moveXY(CopperCoinX, CopperCoinY)
    elif enemy:
        if hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("shield"):
            hero.shield()
        elif hero.isReady("bash"):
            hero.bash(enemy)
1 Like

So you might want to use the protals

1 Like

What is a protal?
Im kinda new to coding in general

1 Like

Its because your using findItems which is a array.

1 Like

What should i use in its stead

1 Like

You can either use a while loop, for loop or findNearestItem.

1 Like

I put in FindNearestItem but it returned "can not write returned property

1 Like

Here is how you find portals

portal = findNearestPortal()

You might want to do something like

portal = findNearestPortal()
if portal and hero.time >= 30:
    hero.move(protal.pos) or hero.moveXY(hero.pos.x, hero.pos.y)
2 Likes

I can’t use FindNearestPortal

1 Like

Lowercase f, hero.findNearestItem()

1 Like

Still doesn’t work. it keeps saying “Can’t write protected property: Value”

while True:
    enemy = hero.findNearestEnemy()
    coin = hero.findNearestItem()
    GoldCoin = coin.value = 3
    SilverCoin = coin.value = 2
    CopperCoin = coin.value = 1
    if GoldCoin:
        GoldCoinX = GoldCoin.pos.x
        GoldCoinY = GoldCoin.pos.y
        hero.moveXY(GoldCoinX, GoldCoinY)
    elif SilverCoin:
        SilverCoinX = SilverCoin.pos.x
        SilverCoinY = SilverCoin.pos.y
        hero.moveXY(SilverCoinX, SilverCoinY)
    elif CopperCoin:
        CopperCoinX = CopperCoin.pos.x
        CopperCoinY = CopperCoin.pos.y
        hero.moveXY(CopperCoinX, CopperCoinY)
    elif enemy:
        if hero.isReady("punch"):
            hero.punch(enemy)
        elif hero.isReady("shield"):
            hero.shield()
        elif hero.isReady("bash"):
            hero.bash(enemy)
1 Like

the elif statement is never gonna run because you will always have a coin. You can do something like if enemy and hero.distanceTo (enemy) < 5
This also applies to coins if coin and coin.value == 3

1 Like

It still didn’t work

1 Like

I just came back to coding and it was properly defining again?
I didn’t change anything and I am confused how it happened but i am happy it decided to actually work so im not going to look a gift horse in the mouth and just go with it

3 Likes

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.