Level: Leave it to Cleaver

I searched for the full code here, but haven’t seen it, so here’s mine, that worked:

Mod edit: Please do not post final solutions.

when i use this code there are only 2 ogres left

This shows how to define a function called cleaveWhenClose

The function defines a parameter called target

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
ready = hero.isReady(“cleave”)
hero.cleave(enemy)
# else, just attack target!
else:
hero.attack(enemy)

This code is not part of the function.

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)
this is all my code including the hints with the #'s

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly

1 Like

This shows how to define a function called cleaveWhenClose

The function defines a parameter called target

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
ready = hero.isReady(“cleave”)
hero.cleave(enemy)
else:
enemy = hero.findNearestEnemy()
hero.attack(enemy)

This code is not part of the function.

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)

not working for some reason

Hello,

Please create only one post for a problem. Adding to multiple topics won’t increase the help you get since everyone sees all of the new posts. I started working on your problem on the other topic.

Thank you dudes Sooo much for helping me solve the puzzle!! I was stuck on it for months, and it was kind of a bug for me.

This shows how to define a function called cleaveWhenClose

The function defines a parameter called target

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
hero.cleave(enemy)
# else, just attack target!
hero.attack(enemy)

This code is not part of the function.

while True:
enemy = hero.findNearestEnemy()
if enemy:
# Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy)

Hi @YaYeetingBOI, please read this topic to learn how to format your code properly:

Thanks
Danny

# This shows how to define a function called cleaveWhenClose
# The function defines a parameter called `target`
def cleaveWhenClose(target):
    if hero.distanceTo(target) < 5:
        pass
        # Put your attack code here
        # If cleave is ready, then cleave target
        hero.cleave(enemy)
        hero.attack(enemy)
        hero.attack(enemy)
        hero.moveXY(50, 12)
        hero.attack(enemy)
        # else, just attack `target`!
        hero.attack(enemy)
# This code is not part of the function.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        # Note that inside cleaveWhenClose, we refer to the `enemy` as `target`
        hero.attack(enemy)
        cleaveWhenClose(enemy)
findAndAttacknereastenmey


no matter how hard I try it won’t work. The only actions that happen are under If cleave is ready, then cleave target

nevermind i figured it out thanks though


I also use Sir Tharin Thunderfist, and it’s still not working!!!

here is my code it is in javascript

mod edit do not post final solutions

Never mind, I got it to work.

def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
#cleave command
else:
#attack command
while True:
target = hero.findNearestEnemy()
if target:
if hero.distanceTo(target) < 5:
if hero.isReady (“cleave”):
#cleave command
else:
#attack command

This isn’t working. I tried it and the munchkins beat me. The character didn’t respond, it only stood there.

// This shows how to define a function called cleaveWhenClose
// The function defines a parameter called target
function cleaveWhenClose(target) {
if(hero.distanceTo(target) < 5) {
// Put your attack code here
// If cleave is ready, then cleave target
if (hero.isReady){
hero.cleave(enemy);
}
// else, just attack target!
else{
hero.attack(enemy);
}
}
}
// This code is not part of the function.
while(true) {
var enemy = hero.findNearestEnemy();
if(enemy) {
// Note that inside cleaveWhenClose, we refer to the enemy as target.
cleaveWhenClose(enemy);
}
}

Hi @YT_DropTheBeat, welcome to the CodeCombat Discourse! :tada:
Please could you format your code so I can see the indents and help you with your code, here’s a topic which explains how to format your code:

@Hexamix_Legend, please could you also format your code.
Thanks
Danny

Hi! Sorry for the late response. I actually managed to finish the level, but thanks for the offer!

1 Like