I need help on my code for kithgard brawl 2

here is my code

loop:
enemy = self.findNearestEnemy()
item = self.findNearestItem()
if item:
pos = item.pos
x = pos.x
y = pos.y
self.moveXY(x, y)
if enemy:
if self.isReady(“cleave”):
self.cleave(self.findNearestEnemy())
if self.isReady(“bash”):
self.bash(self.findNearestEnemy())
else:
self.attack(enemy)
self.attack(enemy)
self.attack(enemy)
self.attack(enemy)

Hello dean, Can you format your code properly as in FAQ.
Thank you.

What are the problems I can only see one in else: yet I don’t know how to fix it yet but you can try to get around codes without or find out what is messing with else okay.

This isn’t really a coding error, but you don’t need the self.findNearestEnemy() in the cleave and bash lines.

What do you need help with? You say you need help, but you don’t tell us what with.

sorry i figured it out thx anyways

my code is this:

loop: 
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if item:
        pos = item.pos
        x = pos.x
        y = pos.y
        self.moveXY(x, y)
    if enemy:
        self.attack(enemy)

    else:
        self.shield()

my hero just keeps dying in the first 30 seconds

Hello, lazerA, and welcome. Please read the FAQ before you post again. It is essential that you learn how to properly format your code. I’ve done it for you this time, but do so yourself in the future.

As this is Kithgard Brawl, there is no “official” solution to it. Unfortunately, all I can suggest is to progress further in the game before returning to this level.

I’m already on sarvern shepherd.
I have 3762 gems

Oh yeah, my hero dies in the first few seconds in sarven shepherd

I just got sword of the forgoton. I solved sarven shepherd.

This topic is about Kithgard Brawl. There is no place here for talking about Sarven Shepherd.

1 Like

It might be a bug or it can be your health :smile:

XD
You ask for help, then say you got over it? this makes me laugh.
Talking to the Dean person.

1 Like

I need the code for the kitgard brawl

@ChronistGilver, please help you seem like a professional I am a measly noob please help my code is bellow.

enemy = hero.findNearestEnemy()
hero.attack(enemy)
hero.attack(enemy)

Hi @akihiko_kahyaba, unfortunately ChronistGilver is no longer active so he won’t be able to answer you. I can however!
For a brawl it’s essential to make a good attacking loop. That means that you have a while True loop which will constantly loop for the whole level and refresh variables like enemy. That means that if a new enemy appears right next to you, you attack the new enemy rather than the enemy that was nearest to you the first time you defined enemy.
Also, if you put your code in a loop, you don’t need to repeat the hero.attack(enemy), it will automatically repeat as long as the enemy exists.
Make sure you also put if enemy: in your loop to check if an enemy exists. These concepts may be a bit confusing at first, but they will become more clear as you continue in the forest.
Also put on your best armour and best rings etc…
Danny

2 Likes

@Deadpool198 thank you here is my code belowwhile True: <enemy = hero.findNearestEnemy() if enemy: hero.shield("hero") hero.attack(enemy) else: hero.moveXY(40, 34)>

I think if you shield it’s better not to attack, because when you are attacking you are not shielding.

I would agree. Mixed shielding-attacking strategies don’t work that well. Also, it’s hero.shield() not hero.shield(“hero”).

1 Like

ok I will try to get a few hundred gems so I can get a good sword