Help, “Stop Audio” button Crashing Cabbage – Csound Noobs

This is the code I’m trying to figure out, honestly I’m not the greatest with code so fairly clueless

; Define instrument 101 to handle play/stop button presses and playback
instr 101

kButton1 chnget "playButton1"


if (kButton1 == 1 && gkPlayFlag1 == 0) then
    event "i", 1, 0, -1 ; Play instrument 1 indefinitely
    gkPlayFlag1 = 1 ; Set the play flag for the first audio file
endif

kStopButton1 chnget "stopButton1"

if (kStopButton1 == 1 && gkPlayFlag1 == 1) then
    turnoff2 1, 0, 0 ; Stop instrument 1
    gkPlayFlag1 = 0 ; Reset the play flag for the first audio file
endif

endin

This is the result that comes out in the code and seems to be an infinite loops which causes the crash but i’m not sure how to fix it. rtevent: T 16.631 TT 16.631 M: 0.00096 0.00101 diskin2: opened ‘C:############\Desktop\TEST\ambience1.wav’: 44100 Hz, 2 channel(s), 11356592 sample frames

Read more here: Source link