def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if enemy:
hero.cleave(enemy)
if enemy:
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)
if enemy:
hero.attack(enemy)
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if enemy:
hero.cleave(enemy)
if enemy:
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)
if enemy:
hero.attack(enemy)
i’m using python cause mah robotics using python and im stuck too and u can’t use just else: but if u use if/else:, it will become if enemy: meaning if there is enemy and ur hero attacks it
Hi, I used the below code and it keeps waiting for the cleave to load instead of going back to attacking the nearest enemy. What’s wrong with my code? Thanks in advance.
# 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
if enemy:
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)
My hero would fight through until the last 21 seconds the hero stops I don’t know what is wrong with my code
I think I didn’t quite catch what you have said I tried doin the hero.cleave (enemy) by it self and still didn’t get anywhere could you help me again sorry if I too much of a bother here is my new code
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if enemy:
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)
Well, not quite there yet. If you don’t test to see if the hero is ready to cleave, then he will attempt to do so, ready or not. This means he may just stand still, until the cooldown period ends.
I just noticed something else too. You are passing the object ‘target’ to your function, but then don’t use it. ‘target’ is actually the enemy you want to be working with in the code. You don’t need to test for enemy again, as you’ve already done that in the code that is calling this function.
Here’s an outline (not code) of how it might look:
def cleaveWhenClose(target):
if hero is closer than 5 meters to the target, then:
if hero is ready to cleave the target, then:
cleave the target!
otherwise:
kill the target!
@dedreous
I tried that and still near the end there are 3 ogre popping out and my hero won’t go to defeat them and then it would just stop
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if enemy:
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)
def cleaveWhenClose(target):
if hero.distanceTo(target) < 5:
pass
# Put your attack code here
# If cleave is ready, then cleave target
if target:
hero.isReady("cleave")
hero.cleave(target)
# else, just attack `target`!
else:
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)
Another tip…the pre-populated comments are typically indented to the spot where you should be adding your code. In other words, these two should align evenly: