Total Noob - Variables in Sleep?

Hi, I’m a total noob playing with Sonic Pi and some Y8s.

Is it possible to do maths (or use variables) with Sleep?

For example, if you want a loop to sleep for 3 times the duration of a sample?

Or you want to do something like:

5.times do
sample :bass_drop_c
sleep x-0.1
end

Such that the sleep value gets slightly shorter each time?

Hi,

thanks for your question :slight_smile:

It’s totally possible to use variables in Sonic Pi - simply use the = operator to assign a value to a letter:

x = 3
5.times do
  sample :bass_drop_c
  sleep x
  x = x - 0.1
end
1 Like

Great! I was trying similar but didn’t quite get the syntax right. Thanks!

1 Like

you could also use the x -= 0.1 syntax to reduce the value of x

1 Like