In your function, you unnecessarily define a variable “ready” and then don’t even call it anywhere. This line should be removed and replaced with an if conditional, if hero.isReady("cleave"): and then tab everything over accordingly.
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
if hero.isReady("cleave"):
hero.cleave(target)
else:
hero.attack(target)
while True:
target = hero.findNearestEnemy()
if target:
cleaveWhenClose(target)
Hi I am having trouble with this level and I need someone to plz reply to me as soon as possible here is my code plz tell me how to improve it because my hero dies after 21 seconds
# 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(target)
# else, just attack `target`!
hero.attack(target)
# 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)
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(target)
# else, just attack `target`!
else:
hero.attack(enemy)
idk why but it just leaves me with one ogre left. i wish i could use my claymore sword but it is restricted. i need help DESPERATELY! It just doesnt give me enough time!