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()
1 Like
my hero doesnt even summon troops or collect coins
Serg
January 29, 2016, 5:55pm
3
At that moment, the variable friend
doesnāt exist. Look at the line above it.
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()
if i delete the s on friends it says try self.findFriends()
Serg
January 29, 2016, 5:57pm
6
You have 2 āmainā loops and one empty function.
def commandTroops():
Has no code inside of it. (Check your indentions.)
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()
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()
Serg
January 29, 2016, 6:01pm
9
When you get that error, do you have any friends on the field?
Your indentations are still wrong.
lundor5
January 29, 2016, 6:02pm
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()
lundor5
January 29, 2016, 6:02pm
11
i dont how how it should be indented
Serg
January 29, 2016, 6:03pm
12
Itās fine to go back and do previous levels to review how things should be indented, then.
lundor5
January 29, 2016, 6:03pm
13
im not sure what my code should be
lundor5
January 29, 2016, 6:04pm
14
im going to try using my code from steelclaw gap
lundor5
January 29, 2016, 6:06pm
15
sorry clicked something there by accident i was going to try my code from steelclaw gap but found it wont help
lundor5
January 29, 2016, 6:09pm
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()
lundor5
January 29, 2016, 6:11pm
17
i feel like there might be a bug in summoning troops and collecting coins cause my hero does nothing
lundor5
January 29, 2016, 6:21pm
18
i give up i cant figure it out
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
lundor5
February 9, 2016, 5:44pm
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()