I used peasant.findNearestItem() in other levels and didn’t get the error messasge.
# Collect all the coins!
def findNearestItemInArray(array, peasant):
item = peasant.findNearestItem() #<---E---R---R---O---R--- peasant has no method findNearestItem.
for i in range(len(array)):
for singlArray in array:
if singleArray == array[i]:
torf =True
pos = singleArray.pos
return torf, pos
elif singleArray != array and i == len(array):
for i in range(len(array)):
for singlArray in array:
array.remove(singleArray)
torf = False
return torf
def commandPeasant(peasant, coins):
# Find the nearest coin to the `peasant` from the `coins` array,
trof = findNearestItemInArray(peasant, coins)
if trof == True:
pos = findNearestItemInArray(peasant, coins)
# Command the peasant "move" to the nearest coin.
hero.command(peasant, "move", pos)
pass
friends = hero.findFriends()
peasants = {
"Aurum": friends[0],
"Argentum": friends[1],
"Cuprum": friends[2]
}
while True:
items = hero.findItems()
goldCoins = []
silverCoins = []
bronzeCoins = []
for item in items:
if item.value == 3:
goldCoins.append(item)
# Put bronze and silver coins in their approriate array:
if item.value == 2:
silverCoins.append(item)
if item.value == 1:
bronzeCoins.append(item)
commandPeasant(peasants.Aurum, goldCoins)
commandPeasant(peasants.Argentum, silverCoins)
commandPeasant(peasants.Cuprum, bronzeCoins)