Leave it to cleaver,,, pls help

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.isReady
hero.cleave (target)
# else, just attack target!
hero.attack(target)

This code is not part of the function.

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

Put your code inside the dots

idk what u mean im using python

Sorry, when you format your code, put your code inside the dots. It’s really helpful when it’s formatted.

# 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.isReady
        hero.cleave (target)
        # else, just attack `target`!
        hero.attack(target)

# This code is not part of the function.
while True:
    target = hero.findNearestEnemy()
    if target:
        # Note that inside cleaveWhenClose, we refer to the `enemy` as `target`.
        cleaveWhenClose(target)
^

Ah, thank you (2000)

I believe it’s impossible for you at the moment. And if other people would write code instead of you - that wouldn’t be your grade in the end, right?)

Anyway…

def cleaveWhenClose(target):
    if me.distanceTo(door) < 1:
        if me.isReady("open"):
            me.open(door)
        else:
            me.knock(door)

That’s what I mean talking about logic of your code and operators/conditions.

1 Like

Yes, you need an if In front of hero.isReady and an else in front of hero.attack (target)

I like your illustrations. :slight_smile:

1 Like

what is that? this part may be what is bugging you if I am aware that there is no function in CodeCombat that uses this

hero.cleave (target)

remove the space

hero.cleave(target)

@ac3, have you solved this, or do you need more help?

i solved it thx for asking tho

1 Like

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