Sound responses - do they need to be reset?

URL of experiment: flanker_basic [PsychoPy]

Description of the problem: inconsistent response sounds

Hi there,

Bit of background:
In my version of the flanker experiment I have two different conditions - a block of keyboard response trials and a block of touchscreen trials (set up using the mouse component). For both conditions I am having the same problem - so I will outline for keyboard condition but it is the problem for mouse condition as well.

For each trial I have three routines in the loop. The first is an initiation routine (participant initiates trial by pressing the 5 key). The next routine is the trial routine (flanker arrows shown and the participant must make a response to either the left (4 key) or right (6 key). In my conditions file I have the correct_response column with R1 (for when a 4 key needs to be pressed) or R2 (for when a 6 key needs to be pressed). The third routine is the feedback routine, where I include the code set out below, and have two sound components (correct_ding and incorrect_buzz). These components have an mp3 file in each of them with the different sounds. If the participant has a correct response, they get correct ding, and for an incorrect response they get an incorrect buzz.

My problem

The problem I am having is that if a participant make an incorrect response, they get the incorrect buzz, but in the subsequent trial if they make a correct response they will get an incorrect buzz rather than a correct ding. Then in the trial after that if they make a correct response they will get the correct ding. So it is almost like the keyboard response is taking two trials to reset or something? Any help gratefully received! Thanks very much!

Begin routine:

accuracy = 0;
response_keys = keys_trials_response.keys;
if ((response_keys === "4")) {
    if ((correct_response === "R1")) {
        accuracy = 1;
        correct_ding_2.play();
    } else {
        incorrect_buzz_2.play();
    }
} else {
    if ((response_keys === "6")) {
        if ((correct_response === "R2")) {
            accuracy = 1;
            correct_ding_2.play();
        } else {
            incorrect_buzz_2.play();
        }
    }
}
psychoJS.experiment.addData("accuracy", accuracy);

Update:

Please ignore this question, I now have this working using a different approach to sound components - soring correct responses using the functionality within the keyboard/mouse components, and then using the code in a response routine, with only one sound component:

Begin experiment:
soundfile = ['correct.wav', 'incorrect.wav']

Begin routine:

if keys_trials_response.corr:
    playsound = soundfile[0]
else:
    playsound = soundfile[1]