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

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

#22

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:

#23

So that code you just posted does not work?

1 Like
#24

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
#25
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
#26

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
#27

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