Delay Loop

Delay loops were usually a for loop designed to pause the game for a second or two. They were used to keep all the text of a chunk from being displayed at once. The usual delay loop looked like this :

print "You are dead."
for d = 1 to 2000:next d
input "Play again? (y/n)", a$

This was great when computers were slower. With modern computers, this approach doesn't work as well. The first problem is that modern computers are faster and will blow through a for loop with blazing speed. The second problem is that in the modern computer era people have computers of differing speeds.

These days, it is better to use sleep:

print "You are dead."
sleep 2000
input "Play again? (y/n)", a$

sleep also has another feature - if the player presses any key, the game will continue, even if the number of milliseconds has not elapsed. This is useful if the player doesn't want to wait.

Related Pages

Categories: Game Programming : Loops : Timing
page_revision: 5, last_edited: 1237839645|%e %b %Y, %H:%M %Z (%O ago)