Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

[SOLVED] TypeError: Cannot Read property X

Hi, can anyone tell me what this probelm is? I’m confused it says Cannot read property “x” I tried 2 ways both didnt work.


Thanks

Can I see the whole code? Maybe there is a mistake in your code that I can not see from those screenshots…

Andrei

Full code, its a bit long cuz i’m in The Trials Level

# This level is intended to be for advanced players. The solution should be pretty complex with a lot of moving parts. It might also be a bit of a gear check unless you use creative methods.
# You need to make your way to the first trial (Oasis of Marr) defeating enemies along the way. When you reach it, pick all the mushrooms to trigger the trial to begin. If you survive the onslaught, make your way to the next Oasis for the second trial, then the Temple. When all trials are complete you will have to face the final boss. Good luck!
# HINT: Glasses with a high visual range help tremendously on this level so buy the best you can get.
# HINT: the unit 'type' for the oasis guardians is 'oasis-guardian'

def Die(enemy):
    enemies = hero.findNearestEnemy()
    if hero.distanceTo(enemy) <= 10:
        hero.cast("drain-life", enemy)
    elif hero.distanceTo(enemy)>= 50:
        hero.attack(enemy)
while True:
    enemy = hero.findNearestEnemy()
    enemies = hero.findEnemies()
    if enemies:
        if hero.canCast("raise-dead"):
            corposes = hero.findCorpses()
            if corposes > 5:
                hero.cast("raise-dead",)
        if hero.canCast("summon-burl"):
            hero.cast("summon-burl")
        if hero.canCast("summon-undead"):
            hero.cast("summon-undead")
        if enemy:
            Die(enemy)
    items = hero.findItems()
    if items:
        hero.moveXY(items.pos.x, items.pos.y)
    flag = hero.findFlag("green")
    if flag:
        hero.moveXY(flag.pos.x, flag.pos.y)
        hero.pickUpFlag(flag)


Here items is an array. Try to loop over all of yhe items and move to each single one of them.

Andrei

1 Like

Thanks for the help it worked

1 Like

No problem! :slightly_smiling_face:

Andrei

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

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