Why should you make it easy when you can make it difficult?
See video
and code ( not fully working, do not delete):
points = [{"id": "Fidsdale", "x": 20, "y": 31, "fl": 0},
# put into points array all archer ids and
# x, y points where the hero must build things
]
speakers = []
things = []
def onHear(event):
message = event.message
speakers.append(event.speaker)
replacements = [',', '!', '!','.', '–'] # '–' very obscure char
for r in replacements:
message = message.replace(r, '')
words = message.split(" ")
word = [e for e in words if e in ["Yak", "Ogre"]][0]
if word == "Yak":
things.append("fence")
elif word == "Ogre":
things.append("fire-trap")
pet.on("hear", onHear);
i_builts = 0;
while True:
length = len(speakers)
if length:
speaker = speakers[length-1]
while speaker:
for point in points:
if point.id == speaker.id:
while not point.fl:
if hero.built.length == i_builts:
hero.buildXY(things[length-1], point.x, point.y)
else:
point.fl = hero.built.length
i_builts +=1
break;
break;
hero.move(Vector(39, 37));
The code is too complicated and hard to explain. Can you help me to simplify it ( keeping the original idea - No Flags ) and make it comprehensible by a 10 years old?