SARVEN DESERT: Help with Sarven Brawl using the Python Coding Language

I have the boss star (from Cloudrip mountain) and used it in this code.

This is for the 2nd or 3rd level of Sarven Brawl im not sure, but heres a pic of the level title thing:

Code:

So that code you just posted does not work?

1 Like

Well now it works, I played othe levels and bought a more powerful sword and my hero survives with 40 HP left. So I am going to buy better armor to get more HP. The code is fine, it was my hero that was wrong.

1 Like
while True:
    enemy = hero.findNearestEnemy()
    enemyX = enemy.pos.x
    enemyY = enemy.pos.y
    NmoveX = hero.pos.x + 2
    NmoveY = hero.pos.y + 2
    if(enemyX<60 or enemyX>60&enemyY<60 or enemyY>60&enemy):
        hero.moveXY(NmoveX, NmoveY)
        hero.attack(enemy)
    else:
        hero.moveXY(59, 70)

I am having the same problem with the same level and this code I am using right now usually works for other levels since the enemies are closer, but since the enemies are too far this doesn’t seem to work, is there a way I could fix it? (Problem is it keeps saying “Try hero.pos” and I have tried using hero.wait as well)Preformatted text

1 Like

Hi @BRIAN_NGUYEN, welcome to the CodeCombat discourse.
You haven’t actually checked whether there is an enemy, only what it’s X and Y .pos is.
I hope this solves your problem.
:lion: :lion: :lion:

1 Like

I think this line of code is giving you some trouble. By checking greater than 60 or less than 60 you are essentially looking everywhere. Also, you want to break up the “or” statements using () . One last thing, I don’t think Python recognizes “&”. Below checks for your X range and Y range and enemy. Fill in the words with the numbers.

if((enemyX<right side or enemyX>left side) and (enemyY<top or enemyY>bottom) and enemy):
1 Like

the problem with your code is you omitted if enemy:

Why enemyIndex???
use for loop
instead of…

while True:
    enemies = hero.findEnemies()
    Index = 0
    while Index < len(enemies):
        enemy = enemies[Index]
        while enemy.health > 0:
            hero.attack(enemy)
        enemyIndex += 1
    pass

use…

while True:
    for enemy in hero.findEnemies():
        while enemy.health > 0:
            hero.attack(enemy)
    pass

Hi, I’ve mentioned this before more than once,
Please don’t post on old level help topics. It clutters the forum and provides absolutely no help to the people on the topic.
Go to the person your replying to’s profile page, and look at the last seen date. It’s probably ages ago. And besides, even if they’re still active, they’ve probably finished the level.
Thank you
Danny

untillTime=0
def attackf(untillTime):
    while True:
        enemy = hero.findNearestEnemy()
        if enemy.type != "sand-yak" or enemy.type == "thrower" or enemy.type == "orgre" or enemy.type == "scout":
            hero.attack(enemy)
        else:
            hero.attack(enemy)
        if hero.time > untillTime:
            break
    pass
hero.moveXY(88, 72)
attackf(30)
hero.moveXY(25, 27)

1 Like

can someone please help me it says cannot read property ‘type’ of null please help me

1 Like

Try to write:

if enemy and enemy.type != "sand-yak" or enemy.type == "thrower" or enemy.type == "orgre" or enemy.type == "scout":
1 Like

ok thank you

1 Like

So you solved it? (20 chars)

1 Like

um no and idk why its not working but it just stays still after killing some enemies

and also it says on line five where you gave me the suggestion it says cannot read property type of null