Question about sync

Here, you have some code outside a live_loop, and some other code inside a live_loop.

Code in a Sonic Pi (Ruby) file is interpreted from top to bottom - in this case, this means the code not in the live_loop is interpreted first (this being the 8.times loop) and 8 times, a cue is sent, a note is played, and the script waits for a little time.

Once that has all finished, the live_loop is interpreted and immediately created by Sonic Pi. By this time, all the cues are in the past.

This means that the sync continues waiting for a cue that will never come.

Sam explains this fairly well I think in the issue I raised a few years back:

The reason it works after you re-run is because by that time, Sonic Pi has already interpreted and created the live_loop, (which it did in the first run) so it is already listening by the time the 8.times loop executes, and is able to respond.

Hope that helps! there are a few diagrams in some of the comments on the topics I link to above that might help to show it visually as well :slight_smile: (Live loops Sync questions :-) - #18 by Martin for example)

1 Like