for soldier in soldiers:
self.command(soldier, "attack", enemy)
is good but there are a few things missing:
#1 What is the value of soldiers?
#Use a self.findFriends() to give him a value
for soldier in soldiers:
#2 How about enemy?
#Use soldier.findNearestEnemy()
#3 What if enemy does not exists?
#Use if enemy:
self.command(soldier, "attack", enemy)
ldiers = self.findFriends()
soldierIndex += 1
soldier = soldiers[soldierIndex]
for soldier in soldiers:
enemies = soldier.findEnemies()
enemy = soldier.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
self.command(soldier, "attack", enemy)
You ate the beginning of soldiers on the first line
It is strange but for solider in soldiers seem to return dead solider also.
I put an if solider: to make sure I only command alive ones
soldiers = self.findFriends()
for soldier in soldiers:
if soldier:
enemies = soldier.findEnemies()
enemy = soldier.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
self.command(soldier, "attack", enemy)
You still need the gathering gold and summoning soldiers parts but I see some code posted earlier.
Get rid of your self.say, each one takes 1 second and they slow you down
# Gather coins to summon soldiers and have them attack the enemy
loop:
items = self.findItems()
item = self.findNearest(items)
itemPos = item.pos
x = itemPos.x
y = itemPos.y
# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
self.moveXY(x, y)
# If you have funds for a soldier, summon one.
if self.gold > self.costOf("soldier"):
self.summon("soldier")
# Use the 'attack' command to make your soldiers attack.
#self.command(soldier, "attack", enemy)
soldiers = self.findFriends()
soldier = soldiers[soldierIndex]
for soldier in soldiers:
if soldier:
enemies = soldier.findEnemies()
enemy = soldier.findNearest(enemies)
if enemy:
# Loop over all your soldiers and order them to attack.
self.command(soldier, "attack", enemy)
this is my code
self.buildXY(âarrow-towerâ, self.pos.x, self.pos.y)
loop:
self.shield()
i think this is what is was not supposed to do i just used shield and acted as a meat shield while my arrow-tower killed everything