VSYNC (Command)

V1
Indications are,  in SmileBasic V1 is identical to that in V2. Also,  can be used in place of , which is not available in V1: the effects of   can be achieved with.

V2
is a command which takes one numerical parameter, which gets rounded down, and pauses execution of the program: in that respect, it is very similar to, but the details differ.

When a program starts executing, and at the end of every  and   command, a clock is reset. Once every 1/60 of a second, i.e. once every frame, the physical displays are updated to reflect the current state of the display buffers, and at the same time, this clock is incremented. The  command will wait until the value of this clock matches the command's parameter, if it has not reached or exceeded that value already. (A negative parameter will generate an  error.)  And when   is finished, as already mentioned, the clock is reset to 0.

For example,  takes very little time. , when the clock is at 0, will wait for the next tick of the frame clock; when the clock is at 1 or more, it will take very little time. when the clock is at 0 will wait 2 ticks, when the clock is at 1 will wait 1 tick, and when the clock is at 2 or above will take very little time.

A common use of  is for reducing or eliminating animation flicker, and making gameplay smoother. Consider a typical game superloop: draw the current state of the game, calculate the next state of the game, repeat. If there is, say, a  just before the 'draw' code, this will ensure that one pass through the loop will never take less than 5 frames. If it is known that the draw and calculate sections together will never take more than 5 frames (and there are no other  or   commands), the command ensures that the update rate is once per 5 frames, exactly, always: if the loop, unsynchronized, would 2 frames sometimes, and 4 frames other times, the player will not notice any difference in gameplay when the appropriate   is included. And if it takes less than one frame to complete the draw phase, and it is immediately after the, the display will never show a half-drawn image.

In summary,  waits until the clock reaches   if it has not already, and resets the clock. If it does wait, it terminates on a frame clock 'tick', which is the best time to start drawing.

V3
No information on SmileBasic V3.