No. Like this:
while True:
commandAttack()
strategy = chooseStrategy()
if strategy=="griffin-rider":
#here summon a griffin-rider
elif strategy=="fight-back":
heroAttack()
elif strategy=="collect-coins":
pickUpCoin()
1 Like
Sorry. I sent the wrong post earlier.
2 Likes
it still doesn’t work. here’s the code:
def chooseStrategy():
enemies = hero.findEnemies()
if hero.costOf("griffin-rider"):
return "griffin-rider"
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if enemy.pos.x < 34:
return "fight-back"
return "collect-coins"
def commandAttack():
friends = hero.findFriends()
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
pass
def heroAttack():
enemy = hero.findNearestEnemy()
if enemy.health > 0:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
if strategy == "griffin-rider":
hero.summon("griffin-rider")
commandAttack()
elif strategy=="fight-back":
heroAttack()
elif strategy=="collect-coins":
pickUpCoin()
You can delete this but only If you want.
2 Likes
Here put
if hero.gold >= hero.costOf("griffin-rider"):
return "griffin-rider"
2 Likes
I also told you that in post 3.
Does it work now?
2 Likes
yes it does. thanks @AnSeDra!
2 Likes
No problem! Glad I could help! And congratulations for completing the level!
2 Likes
system
Closed
32
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.