# 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("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 my code. it isnt working again, leaving me with one munchkin left or 3 that kill me.
P.S this code is Python
Hi I am having trouble with this level and I need some help iām like stuck on this for 6 days. Plz reply to me ASAP. When i do my code it leaves 2 enemies behind. I honestly donāt know anything to do. Plz help me.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)
this is my code plz help me to improve it.
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)
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)
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)
I found I needed to put a hero.moveXY command in to the while True loop, so the hero moves back to the middle of the screen regularly. Otherwise she ends up fighting right at the top of the screen and misses some enemies with the cleave function.