You start with 360 gold to build a mixture of soldiers and archers.
self.built is an array of the troops you have built, ever.
Here we use “len(self.built) % len(summonTypes)” to wrap around the summonTypes array
def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold >= hero.costOf(type):
hero.summon(type)
def commandTroops():
friends = hero.findFriends()
for i in range(len(friends)):
friend = friends[i]
# Use % to wrap around defendPoints based on friendIndex
point = defendPoints[len(friends) % len(defendPoints)]
# Command your minion to defend the defendPoint
hero.command(friend, “defend”, point)
while True:
summonTroops()
commandTroops()
What am I doing wrong?! I’ve had bugs on some levels, and there’s no clear reason why this code isn’t working! The only result I ever get is all the units are summoned and they all go to the top left corner! Please tell me there’s a bug in this level!
that doesn’t work either; I’d have to define friendIndex which would have to equal 0, because the friend variable is already defined as friends[i]. that’s why i think this level is bugged.
Please learn to post your code properly from the game from now on and use the </> button or it won’t format properly. When you click the </> button, the following will appear:
There are many people here willing and able to help. If you use the </> button correctly, your code should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.say("My code is formatted properly")
If your code doesn’t look like the code above, then you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you.