Play audio for correct key response only

Our experiment is a naming experiment, where a photo pops up on the screen and if said correctly, the researcher will press y or n if said incorrectly. There are about 30 photos, so we hope to run through a separate loop for each photo. Currently, the routine no matter if y or n is pressed, it plays the audio and continues with the experiment. We have the audio named properly in the excel sheet as a parameter $audio, and have correct answer listed as a parameter ($correct) and y is listed as the answer for each photo. The key response itself is called properly in the code and matches the variable name. What is our issue?

Our current code for feedback…

Begin experiment:
soundfile = ‘$audio.wav’
loudness = 1

Begin routine:
if key_resp_5.corr:
playsound = ‘$audio’[0]
loudness = 1
else:
playsound = ‘$audio’[1]

What should our code be??? Below is a screenshot of our excel sheet as well.

Hello,
Can you please share the psyexp file/explain some more about your variables? Because it’s not clear at this moment.
What is the meaning of playsound = '$audio' [0] in your experiment?
What is the value of audio?
Please add some more context/examples.

Thanks

Hi, thank you so much for your reply! I’m writing back for my colleague, I’m not the one who wrote the code, but the $audio refers to the spreadsheet (posted in the screenshot) - the third column labeled audio is a list of 30 audio files that each get pulled in to a trial (different sounds for each trial).

I believe my colleagues got the [0] and [1] code from another example that was posted on this forum. What we want to happen is that if the experimenter presses ‘y’, which is labeled as the correct response for “key_resp_5”, the audio should not play and the routine should advance to the next trial. If the experimenter presses ‘n’, which is incorrect, the audio should play.

Let us know what other details would help! Thanks!