wondering what happens when loops take too long for the program to refresh the screen at 40 frames per second.
AGS always runs all the code associated with each frame before displaying it. Once it's done, it checks if 1/40 second has passed (or whatever the game speed is), and if there's time left it waits until the right amount of time has elapsed, displays the frame, and starts processing the code (both AGS-internal and scripted) for the next frame.
So if the script takes more time than that, the game will simply hang until the script is complete, and then move on to the next frame immediately. If this happens every cycle, the effect will be that the game runs more slowly than the game speed (and it can cause the audio to break up, if the audio buffer runs out during the processing).
One caveat: There is a safety feature built in that ensures that if a loop repeats more than a certain number of times in a single cycle, it will break, closing the game, though it can be disabled with the keyword noloopcheck