Hello, I am currently working on making a turn-based combat game, and I was wondering about repeat-until loops.
Currently, the loop runs until either all the enemies or the heroes die, ending the battle. However, in between all of that, each character (and enemy once I script it) will take turns and have unlimited time to take their turn.
This is why there is another repeat-until loop within this one. I was just wondering if the main repeat-until loop will take priority and end when it’s supposed to or if it gives priority to the loop inside of it. I hope that makes sense, and if it doesn’t I can try to explain further. Thanks for any help!
Code like this runs sequentially. That means the outer loop won’t continue until the inner loop finishes.
As for the outer loop ending at the intended time: the outer loop will not end the moment the outer loop’s end condition is met. In addition, it might not end at all if the end condition becomes true while the TurnTaken == true is being waited for but then the end condition becomes false again. (ie if the outer loop is busy waiting on the inner loop it won’t see that the end condition was met.)
The thing above isn’t a problem if the spawned heros and spawned mobs aren’t changed outside the loop.
You can replace your wait loop with something that might be more clear like this:
-- If TurnTaken isn't already true wait for it to change
if hero:GetAttribute("TurnTaken") == false then
hero:GetAttributeChangedSignal("TurnTaken"):Wait()
end