Changing the topic from [HELP] Summits gate: for @SuperSmacker
1 Like
@Chaboi_3000 ok so when i try to get the soldier to kill the shaman and free the archer, and let the archer do the rest, i somehow got an infinity loop for using for friend in friends:
Thanks for your help
Here’s my code:
hero.moveXY(33, 19)
while hero.time < 20:
friends = hero.findFriends()
for friend in friends:
if hero.time < 3.5:
enemy = friend.findNearest(hero.findEnemies())
if enemy:
hero.command(friend, "attack", enemy)
elif friend.type == "archer":
while "Uld'Mak".health > 0:
hero.command(friend, "attack", "Uld'Mak")
elif friend.type == "paladin":
if hero.time < 5:
enemy = friend.findNearestEnemy()
hero.command(friend, "attack", enemy)
elif step < 4:
if soldier.canCast("heal") and hero.now() > 3:
hero.command(soldier, "cast", "heal", soldier)
elif hero.now() > 5 and soldier.health < soldier.maxHealth:
hero.command(soldier, "shield")
elif friend.type == "soldier":
while "Drun".health > 0:
hero.command(soldier, "attack", "Drun")
I see, you didn’t mention anything about. step
1 Like
Convoluted logic –
in the for loop
for friend in friends:
if hero.time < 3.5:
...
elif friend.type == "archer": # AND if hero.time >= 3.5
...
elif friend.type == "paladin":
...
elif friend.type == "soldier":
...
Clear logic would be something like this:
if hero.time < 3:
...
elif hero.time < 10:
...
elif hero.time < 20:
...
else: # when hero.time >= 20
...
And then somewhere inside those statements, you can determine what to do depending on friend.type
.
regarding the while loop
while hero.time < 20:
friends = hero.findFriends()
for friend in friends:
...
# end of while
# ok, so what do you do after the 20-second mark?
Also, I’d suggest making functions for those pieces of code that repeat inside your program.
Useful tips on organizing your code for clarity:
I used several loops.
1 Like
Please do not post working code
Don’t revive dead threads meaninglessly
1 Like