Newbie If/Else issue

Sorry if this is the wrong category for simple questions like this:

I’m trying to make a more dynamic drum loop with some pretty basic language, and I wrote this bit:

sample :drum_bass_soft
sleep 0.5
if one_in 2 do
sample :drum_cymbal_open, lpf: 115, finish: 0.25, release: 0.125
end
else
sample :drum_cymbal_closed
end
sleep 0.5

When I run it, the else statement works, but the if statement just does silence. I’ve messed around with it, but all my troubleshooting has just led to errors, primarily, “else statement useless without escape.”

What is it that I’m not grasping?

Hi there Dominic and welcome.

Try this code:

live_loop :drumbeat do
  sample :drum_bass_soft
  sleep 0.5
  if one_in 2
    sample :drum_cymbal_open, lpf: 115, finish: 0.25, release: 0.125
  else
    sample :drum_cymbal_closed
  end
  sleep 0.5
end

EDIT note you can put three ` on the line before and the line after your code to make it display nicely/

Thanks Robin! And thank you for the formatting tip!