Iguana
1
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
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
Iguana
3
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