Here is the poster's code with the indentation restored and the curly quotes replaced by straight ones, so it's valid Python. The forum post had lost the indentation, so I reconstructed it from the logic.
```python
qnum = x.pop()
soundarray = ['do.ogg', 're.ogg', 'mi.ogg', 'fa.ogg', 'sol.ogg', 'la.ogg', 'si.ogg']
shuffle(soundarray)
sound1 = soundarray.pop()
sound2 = soundarray.pop()
sound3 = soundarray.pop()
sound4 = soundarray.pop()
cuesound = cuearray.pop()
if cuevalid == 'yes':
if cuesound == 'cue1.ogg':
if soundjudge == 'yes':
sound6 = sound1
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue2.ogg':
if soundjudge == 'yes':
sound6 = sound2
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue3.ogg':
if soundjudge == 'yes':
sound6 = sound3
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue4.ogg':
if soundjudge == 'yes':
sound6 = sound4
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuevalid == 'no':
if cuesound == 'cue1.ogg':
if soundjudge == 'yes':
tempsoundarray = [sound2, sound3, sound4]
shuffle(tempsoundarray)
sound6 = tempsoundarray.pop()
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue2.ogg':
if soundjudge == 'yes':
tempsoundarray = [sound1, sound3, sound4]
shuffle(tempsoundarray)
sound6 = tempsoundarray.pop()
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue3.ogg':
if soundjudge == 'yes':
tempsoundarray = [sound1, sound2, sound4]
shuffle(tempsoundarray)
sound6 = tempsoundarray.pop()
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuesound == 'cue4.ogg':
if soundjudge == 'yes':
tempsoundarray = [sound1, sound2, sound3]
shuffle(tempsoundarray)
sound6 = tempsoundarray.pop()
if soundjudge == 'no':
sound6 = soundarray.pop()
if cuevalid == 'nouse':
if soundjudge == 'yes':
tempsoundarray = [sound1, sound2, sound3, sound4]
shuffle(tempsoundarray)
sound6 = tempsoundarray.pop()
if soundjudge == 'no':
sound6 = soundarray.pop()
I am not sure the original indentation was exactly this, but it is the only structure that makes sense of the code. I can think of four reasons why your code fails:
Unexpected values in the conditions file. Examples are 'Yes', 'yes ' with a trailing space, or an empty cell. cuesound can also be wrong if cuearray isn’t what you think it is.
No fallback in the code (silent non-match). Every branch is a separate if without an else. If cuevalid, cuesoundor soundjudge has an unexpected value, sound6 is never assigned. It then keeps its value from the previous trial, or raises a NameError on the first trial. This is the mechanism that turns cause 1 into random-looking behavior.
Component order. The code component must sit above the Sound component in the routine, and the Sound’s sound field must be set to $sound6 with “Set every repeat”.
Sound timing. If sound6 is the same file as another sound, or a sound starts at t=0, the PTB backend can occasionally drop it. A tiny start delay such as 0.05 s helps rule this out.
Causes 1 and 2 are closely linked: the data supplies the unexpected value, and the missing else lets it pass unnoticed.