# If the peasant is damaged, the flowers will shrink!
while True:
enemy = hero.findNearestEnemy()
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friends = hero.findFriends()
for friend in friends:
enemy = hero.findNearestEnemy()
soldiers= hero.findByType("soldier")
for soldier in soldiers:
if friend.type == "soldier":
hero.command(soldier, "attack",enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
peasant = hero.findByType("peasant")[0]
while True:
enemy = hero.findNearestEnemy()
summonSoldiers()
commandSoldiers()
pickUpNearestCoin()
# commandSoldiers()
# pickUpNearestCoin()
if (enemy and hero.distanceTo(enemy)<=5):
if hero.isReady("cleave"):
hero.cleave(enemy)
elif (hero.isReady("bash")):
hero.bash(enemy)
else:
hero.shield()
hero.attack(enemy)
I don’t think that you actually need this, it just complicates things. Try using the while loop just to summonSoldiers(), commandSoldiers(), and pickUpNearestCoin(). Hope this helps!
So like that, wait it still didnt work but is there a way to solve it with this gear: Runesword Deflector boots of jumping boss star 1 promatticon 4 tarnished bronze chestplate and all the other stuff the game makes u buy?
My character gets 1139 hp from the gear, is there a way to work it out with this kind of equipment?
The problem is this. While True loops never end and cannot run concurrently (in this level). At the moment you’re getting stuck on that while True loop and nothing else is running because you haven’t told it to stop.
Danny
This function is a bit confused at the moment. You’re using two for loops (nooo don’t do it!!). Except for looping through two/three+ dimensional arrays, you really don’t need more than one (in CoCo at least).
You’ve checked whether the friend is a “soldier”, so why loop through the soldiers as well.
You can get rid of two lines and that function will work.
Danny
If I show you you won’t learn anything.
You need one for loop.
You need it to command soldiers.
You have a soldiers array and a for loop which goes through it.
Why do you have a friend for loop and the line which checks if the friend is a soldier? The soldier for loop does that for you.
Danny
array = ["apple", "banana", "pear", "orange"]
for item in array:
hero.say(item)
Output:
#-- "apple"
#-- "banana"
#-- "pear"
#-- "orange"
It loops through the array one by one and uses the item (in this case it prints a string).
Soldiers is an array.
So you loop through it:
for soldier in soldiers:
Then you use the variable you’ve made (soldier). In this case you command it to attack it’s nearest enemy. Which you’ll need to define inside the for loop.
So what are these lines?
You’re getting confused inbetween two possible (and both perfectly valid) ways of doing this. You’ll have to chose one.
If you need more help review earlier commanding levels.
Danny
# If the peasant is damaged, the flowers will shrink!
def summonSoldiers():
if hero.gold >= hero.costOf("soldier"):
hero.summon("soldier")
# Define the function: commandSoldiers
def commandSoldiers():
friend = hero.findFriends()
enemy = hero.findNearestEnemy()
soldiers= hero.findByType("soldier")
for soldier in soldiers:
hero.command(soldier, "attack",enemy)
# Define the function: pickUpNearestCoin
def pickUpNearestCoin():
item = hero.findNearestItem()
if item:
hero.move(item.pos)
peasant = hero.findByType("peasant")[0]
while True:
enemy = hero.findNearestEnemy()
summonSoldiers()
commandSoldiers()
pickUpNearestCoin()
# commandSoldiers()
# pickUpNearestCoin()
still doesnt work