Mixed Unit Tactics


#1

its saying try self.findFriends() and line 10friend is not defined i dont know why

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
loop:
    friends=self.findFriends()
    if friend != 'palisade':
        enemies=self.findEnemies()
        for enemy in enemies:
            self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()

#2

my hero doesnt even summon troops or collect coins


#3

At that moment, the variable friend doesn’t exist. Look at the line above it.


#4

this is my new code my it doesnt say anything is wrong but my hero doesnt even summon troops

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
loop:
    friends=self.findFriends()
    for friend in friends != 'palisade':
        enemies=self.findEnemies()
        for enemy in enemies:
            self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()

#5

if i delete the s on friends it says try self.findFriends()


#6

You have 2 ‘main’ loops and one empty function.

def commandTroops():

Has no code inside of it. (Check your indentions.)


#7

i changed it to this and it says hero placeholder needs something to command
def summonTroops():
type=summonTypes[len(self.built) % len(summonTypes)]
if self.gold >= self.costOf(‘archer’):
self.summon(‘archer’)
elif self.gold >= self.costOf(‘soldier’):
self.summon(‘soldier’)
def commandTroops():
loop:
friends=self.findFriends()
for friend in friends != ‘palisade’:
enemies=self.findEnemies()
for enemy in enemies:
self.command(friend, “attack”, enemy)
def collectCoins():
coin=self.findNearest(self.findItems())
self.move(coin.pos)
loop:
summonTroops()
commandTroops()
collectCoins()


#8

sorry

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
loop:
    friends=self.findFriends()
    for friend in friends != 'palisade':
    enemies=self.findEnemies()
    for enemy in enemies:
     self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()

#9

When you get that error, do you have any friends on the field?

Your indentations are still wrong.


#10

no i dont and the error is gone but if i change it to this is says summontypes not defind

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
loop:
    friends=self.findFriends()
    for friend in friends != 'palisade':
    enemies=self.findEnemies()
    for enemy in enemies:
     self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()

#11

i dont how how it should be indented


#12

It’s fine to go back and do previous levels to review how things should be indented, then.


#13

im not sure what my code should be


#14

im going to try using my code from steelclaw gap


#15

sorry clicked something there by accident i was going to try my code from steelclaw gap but found it wont help


#16

is this indented correctly but my hero still doesnt summon troops or go get coins

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
loop:
    friends=self.findFriends()
    for friend in friends != 'palisade':
        enemies=self.findEnemies()
    for enemy in enemies:
        self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()

#17

i feel like there might be a bug in summoning troops and collecting coins cause my hero does nothing


#18

i give up i cant figure it out


#19

You have a loop in the def commandTroops() function. Delete it.

Delete also the second for:

for enemy in enemies:

Each soldier is supposed to attack an enemy. You cannot command a soldier to attack all enemies at one.

You also what search for the nearest enemy for a soldier:

enemy=soldier.findNearestEnemy()

Then command each soldier to attack his closest enemy.

I think there are other issues also but, but try to fix at least these


#20

This is my new code on line 2 it says reference error summontypes is not defined

def summonTroops():
    type=summonTypes[len(self.built) % len(summonTypes)]
    if self.gold >= self.costOf('archer'):
        self.summon('archer')
    elif self.gold >= self.costOf('soldier'):
        self.summon('soldier')
def commandTroops():
    friends=self.findFriends()
    for friend in friends != 'palisade':
        enemies=self.findEnemies()
        enemy=soldier.findNearestEnemy()
        self.command(friend, "attack", enemy)
def collectCoins():
    coin=self.findNearest(self.findItems())
    self.move(coin.pos)
loop:
    summonTroops()
    commandTroops()
    collectCoins()