What glasses are you using? I’m thinking that your ‘while true’ loops are part of the problem. If you have Twilight equipped, you are finding every enemy on the map, so are getting stuck. I used Enchated…gave me infinite range, but not through walls.
Your first inner loop is going to look for enemies forever. Actually, you apparently don’t have Infinity do you? Instead of what I first thought, it appears that you are clearing all line of site enemies and items and then it stops. Doesn’t he need to go around the corner a ways to see the next group of enemies?
Maybe using ‘while true’ is not the best solution? I used a very different strategy, one not using flags, so this is only an educated guess. Perhaps iterating through an array of visible enemies might work better?..it’s a thought