[Cloudrip Treasure] Something went wrong


#1
> def friendApart(friends):
>     friends = hero.findFriends()
>     friendsEast = []
>     friendsWest = []
>     for i in range(len(friends)):
>         if friends[i].pos.x > 100:
>             friendsEast.append(friends[i])
>         else:
>             friendsWest.append(friends[i])
>     for friendEast in friendsEast:
>         item = friendEast.findNearestItem()
>         if item.pos.y > 60:
>             hero.command(friendsEast[0], "move", item.pos)
>         else:
>             hero.command(friendsEast[1], "move", item.pos)
>     for friendWest in friendsWest:
>         item = friendWest.findNearestItem()
>         if item.pos.y > 60:
>             hero.command(friendsWest[0], "move", item.pos)
>         else:
>             hero.command(friendsWest[1], "move", item.pos)
> 
> troopsType = ["griffin-rider", "soldier", "archer", "archer", "griffin-rider"]
>    
> def summomTroop():
>     type = troopsType[len(hero.built) % len(troopsType)]
>     if hero.gold > hero.costOf(type):
>         hero.summon(type)
>     
> def commandTroop():
>     friends = hero.findFriends()
>     for friend in friends:
>         enemy = friend.findNearestEnemy()
>         if friend and friend.type != "peasant":
>             hero.command(friend, "attack", enemy)
> 
> while True:
>     enemy = hero.findNearestEnemy()
>     friendApart()
>     summomTroop()
>     commandTroop()
>     
>     if enemy:
>         if hero.canCast("chain-lightning", enemy):
>             hero.cast("chain-lightning", enemy)
>         else:
>             hero.attack(enemy)

alarm:
type Error: friendWest.findNearestItem() is not a function.

My peasants can go to collect coins when i run the code, even there is an alarm. But after some seconds they stopped, i dont know why. Help!!!


#2

The problem lies in here. You need to define friendsWest a little better with more detail just as you did with friendsEast. Use an elif conditional instead of just an else. The confusion in your code arrises when friends are summoned

troopsType = ["griffin-rider", "soldier", "archer", "archer", "griffin-rider"]

and their x position is < 100.


#3

thank you, that helps. and another problem is when a peasant got killed, the code stopped…:joy: