R_Ross
July 6, 2021, 8:04pm
#1
It says I have an infinate loop, the problem is I don’t see it
j = 0
soldierIndex = 0
soldiers = 0
while True:
item = hero.findNearestItem()
enemy = hero.findNearestEnemy()
if enemy and hero.health >= hero.maxHealth / 2:
while hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
while hero.gold < hero.costOf("soldier"):
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
hero.attack(enemy)
if enemy and hero.health < hero.maxHealth / 2:
while hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
while hero.gold < hero.costOf("soldier"):
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
hero.consecrate()
c = pet.isReady("shapeShift")
if c:
pet.shapeShift()
elif item:
hero.move(item.pos)
else:
hero.move({"x" : 60, "y" : 51})
R_Ross
July 6, 2021, 8:08pm
#2
I can see that my hero instantly chooses to target some gold, meaning he is doing something. But, the game says I have no target. (the game puts the little red circle around the nearest coin marking the fact that my hero has targeted it, but the game then stops.)
R_Ross
July 6, 2021, 8:11pm
#3
I also tries using a healing ring to make it so my code isnt always going to the second “if” after a while, but nope. Nothing. It makes it stop at 3 seconds, (a little longer) but it still stops.
R_Ross
July 6, 2021, 8:16pm
#4
I tried putting "pass’ everywhere, and it goes back to .04 seconds until the game stops.
j = 0
soldierIndex = 0
soldiers = 0
while True:
item = hero.findNearestItem()
enemy = hero.findNearestEnemy()
if enemy and hero.health >= hero.maxHealth / 2:
while hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
pass
while hero.gold < hero.costOf("soldier"):
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
pass
pass
hero.attack(enemy)
pass
if enemy and hero.health < hero.maxHealth / 2:
while hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
k = 1
pass
while hero.gold < hero.costOf("soldier") and k :
while soldierIndex < len(soldiers):
soldier = soldiers[soldierIndex]
hero.command(soldier, "attack", enemy)
soldierIndex += 1
pass
pass
hero.consecrate()
c = pet.isReady("shapeShift")
if c:
pet.shapeShift()
pass
pass
elif item:
hero.move(item.pos)
pass
else:
hero.move({"x" : 60, "y" : 51})
pass
pass
R_Ross
July 6, 2021, 8:18pm
#5
@Chaboi_3000
@Deadpool198
you two have helped before, do you know anything?
I might be able to help.
You might want to use some functions.
Posting all your code in a while loop is very messy.
Also, to command your troops, why not use a for loop?
It’s easier.
Here is a piece of code that makes you summon soldiers, then command them to do stuff.
def command():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
def summon():
item = hero.findNearestItem()
if hero.gold > 20:
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
command()
summon()
Do you want to get coins and summon, or do you want to attack?
R_Ross
July 7, 2021, 12:14am
#7
I want to summon while there are no enemies and attack when there are. But i might have it now
Why not summon in combat?
Soldiers can aid you if your fighting, even if you immediatlly summon them.
Archers, not so much
R_Ross
July 7, 2021, 12:33am
#9
true, but if i do that they only attack one enemy. I need to command them to attack every single time a new enemy appears
R_Ross
July 7, 2021, 12:33am
#10
friendIndex = 0
def charge():
if friend:
friends = hero.findFriends()
soldier = friends[friendIndex]
hero.command(friend, "attack", enemy)
hero.attack(enemy)
if hero.isReady("consecrate") == True:
hero.consecrate()
def collectAndSummon():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
friend = hero.findNearest(hero.findFriends())
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
if enemy:
charge()
elif item:
collectAndSummon()
this is my code right now, and they only attack once as i said.
R_Ross
July 7, 2021, 12:37am
#12
I added some more code and they still only attack once. Am I doing something wrong?
friendIndex = 0
def charge():
if friend:
friends = hero.findFriends()
soldier = friends[friendIndex]
hero.command(soldier, "attack", enemy)
friendIndex += 1
hero.attack(enemy)
if hero.isReady("consecrate") == True:
hero.consecrate()
def collectAndSummon():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
friend = hero.findNearest(hero.findFriends())
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
if enemy:
charge()
elif item:
friendIndex = 0
collectAndSummon()
Look at the code is sent you.
I did FRIEND.findNearestEnemy()
They can attack multiple enemy targets.
I’e tested this code.
Try it.
Some errors in your code:
Consecrate can be used indefinitely:
It heals you, and won’t damage enemies.
Maybe you should only consecrate when you are low.
R_Ross
July 7, 2021, 12:40am
#15
Just did that, same thing.
Its as if i am only commanding one but I should … oh wait
def command():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
def summon():
item = hero.findNearestItem()
if hero.gold > 20:
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
command()
summon()
Use this code.
It will make you get items, summon soldiers, and command them to attack THEIR nearest enemy.
You can customize it to suit your own purposes
1 Like
R_Ross
July 7, 2021, 12:44am
#17
This should work why is the game telling me the len in len[freinds] should be defined?
friendIndex = 0
def charge():
if friend:
while friendIndex < len[friends]:
friends = hero.findFriends()
soldier = friends[friendIndex]
badGuy = friend.findNearestEnemy()
hero.command(soldier, "attack", badGuy)
friendIndex += 1
hero.attack(enemy)
if hero.isReady("consecrate") == True:
hero.consecrate()
def collectAndSummon():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
friend = hero.findNearest(hero.findFriends())
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
if enemy:
charge()
elif item:
friendIndex = 0
collectAndSummon()
R_Ross
July 7, 2021, 12:45am
#18
RangerGrant9307:
def command():
friends = hero.findFriends()
for friend in friends:
if friend.type == 'soldier':
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
def summon():
item = hero.findNearestItem()
if hero.gold > 20:
hero.summon("soldier")
elif item:
hero.move(item.pos)
while True:
command()
summon()
also using this code my hero never attacks. If i dont attack then in a later level of the brawl I will lose
You can make it so if there is an enemy, attack it.
If you have enough gold for troops, summon.
Else, get money