# Manage the queue without mistakes.
# Useful string constants.
PHRASE_IN = " in"
PHRASE_OUT = " out"
IDLE = "idle"
# The list of workers.
workers = hero.findByType("peasant", hero.findFriends())
# Use this array to control the worker queue.
queue = []
workerIndex = 0
while True:
# Iterate through all the workers:
while workerIndex < len(workers):
worker = workers[workerIndex]
# If the worker's "status" property is "idle":
if worker.status is "idle":
# Say the worker's name and the string " in":
hero.say(worker + " in")
# Add the worker to the end of the queue:
workerIndex += 1
item = hero.findNearestItem()
# If the item exists and the queue isn't empty:
if item:
# Say the name of the first worker in the queue
# with the string " out":
hero.say(worker + " out")
# Remove (shift) the first worker from the queue:
workerIndex -= 1
Yep, that’s my code.