We rewrite simple infinite loops that just use while True: to insert a one-frame yield if you don’t take any blocking action. So this:
while True:
if hero.isReady():
hero.cleave()
effectively becomes:
while True:
if hero.isReady():
hero.cleave()
if <no time has passed since the start of the loop>:
hero.wait(0.01)
We don’t do this when the while condition is something more complicated, because maybe you want to loop over an array or something. So time doesn’t pass inside those loops; you’d have to add the hero.wait(0.01) call yourself. wait is available on some of the wristwatches.
In Mages’ Might, though, you just don’t have that API, so you’d have to rewrite your while True: loop like this so that you can take advantage of automatic simple loop yielding:
hero.cast("fire-ball")
while True:
missile = hero.findNearest(hero.findFriendlyMissiles())
print(missile.pos.x)
if hero.color == "red" and missile.pos.x > 50:
break
elif hero.color == "blue" and missile.pos.x < 50:
break
print("End of loop")
I am having trouble with my code, here it is.
hero.cast(“fire-ball”)
while True:
missile = hero.findMyMissiles()
print(missile.pos.x)
if hero.color == “red” and missile.pos.x > 50:
break
print(“End of loop”)
if you could help me fix it I would appreciate it