so ive got the clone part down pat, but im not sure what I need to write for the attack-the-warlock code? i know what i need to do but im not too sure how to do it. neither my hero nor my archers go and attack the warlock, and they just sit there and i run out of time
heres my code (that wont work):
# When all clones disappears, attack the warlock.
enemy = hero.findNearestEnemy()
if enemy:
if enemy.type == "warlock":
while enemy.health > 0:
hero.command(friend, "attack", enemy)
hero.attack(enemy)
Not sure but it seems useful if you give us the rest of your code as well, it might seem ‘‘down’’ for you but can still contain problems. You can always delete it later/ask a mod to delete if you think it’s a possible spoiler for other people.
Please define what ‘‘wont work’’ means here, does your hero refuse to do anything, does your hero die, there are various scenarios.
In case your hero dies because the warlock is too strong (?), maybe see if there are other ways to attack him.
what you can do before this is wait a few seconds, around: 7 secs and i think it would work, that way, you can be sure that this code runs when all the clones are gone
no, i was using the archers in the first place, i had just added my hero in the mix to see if that’d help but it didnt. and @Aya, im not sure what you mean by wait, i havent learned anything about using wait
In your current code it seems to me like you are not commanding all your archers. There is only a line that states how an individual archer could attack, but none of them is attacking at all
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy:
if enemy.type == "warlock":
while enemy.health > 0:
hero.attack(enemy)
hero.command(friend, "attack", enemy)
is this what you mean? because if so it doesnt work
friends = hero.findFriends()
enemy = hero.findNearestEnemy()
for friend in friends:
if enemy:
if enemy.type == "warlock":
while enemy.health > 0:
hero.command(friend, "attack", enemy)
So about the wait, i dont recall a level where they teach it, but if you have a watch with hero.wait, you can use it this way: hero.wait(7) this would make it wait for 7 secs