| Reference | Downloads | Github

Not tracking correct responses for feedback in Pavlovia


I am working on an experiment where participants are asked to watch a series of videos and respond to behaviors (BOI) by pressing specified keys. Their responses must fall within a range of times, and there is a different BOI for each of the 6 videos.

After watching each video, participants receive feedback on how many responses were correct/incorrect based on their key presses. For example, if a participant responds 100% correctly to a BOI, the feedback may say, “You got 4 instances of falling correct” where 4 is the possible number of correct and falling is the BOI.

I have this code at the end routine:

if (psychoJS.eventManager.getKeys(BOI)) {
t = trialClock.getTime();
if (correctRange.some(x => (x[0] < t) && (x[1] > t))) {
correct +=1;
} else {
incorrect +=1;

When I run the experiment on Pavlovia myself, regardless of key presses, all of my responses seem to be counting as incorrect. So, in the above example, even if I press the specified key at the correct time, I am still getting “you got 0 instances of falling correct” as my feedback.

Any help would be very much appreciated!!

It seems to me that it’s worth trying a simpler function. Can you try (in Python auto translated with event defined in code_JS)

if event.getKeys(BOI):
     if t > correctRange[0] and t < correctRange[0]:
          correct +=1
          incorrect +=1

Since this is in End Routine it must be that they can only press one key per routine and that ends the routine, in which case you could just use key_resp_corr instead (i.e. have .corr based on the correct behaviour and then correct based on correct behaviour plus correct time.

Thanks for the suggestion. When I test that code and console.log for correct and incorrect, I always get 1 for incorrect and 0 for correct regardless of whether t is inside the range provided.

Participants are continuously responding throughout the length of the video in the routine. I had had the code in each frame, but that was making the numbers of feedback too high (i.e. 265 instances when there could only be 8 possible correct responses). I moved it to end routine to test it out and realized I was getting the appropriate number of responses for each video i.e. 2, 4, 8), but nothing is being added to correct even when I press the possible keys the correct number of times in the correct time frames.

I’m not sure where I should be keeping track of the key press (i.e. each frame, end routine, etc.) so that it a) checks only the keys the participants pressed against the correct keys and times I provided and b) actually adds the correct responses the participants make.

In End Routine you can only get a score of correct if you are pressing the correct button at the end of the video and that is still in the correct window.

You do want code in the Each Frame tab. To stop getting multiple responses from each key press you need a flag. Set a variable e.g. keyScored=0 in Begin Routine. Only add one to correct if keyScored==0 and then set it to 1

Thank you for the response. I just want to clarify to make sure I understand correctly.

I put this code translated to the JavaScript side of PsychoPy.

(In begin routine)

keyScored = 0

(In each frame)

if event.getKeys(BOI) :
t = trialClock.getTime()
if keyScored == 0
if any(lower <= t <= upper for (lower, upper) in correctRange) :
correct +=1
keyScored = 1
incorrect +=1

Once that code is there, I will stop getting multiple responses from each key press. Would this code only allow my participant to get one correct response for each time the routine runs? I want them to be able to get as many correct as are possible, which is usually more than 1 (it could be up to 8 in my case).

Thank you!

if BOI in keys and keyScored == 0 and t >= lower and t <= upper:
          correct +=1
          keyScored = 1
          incorrect +=1

where lower and upper could be set in Begin Routine or referenced at list items.

I’m reluctant to incorporate your range syntax since I’m not familiar with it and don’t think it’s necessary.

Thanks for the suggestion. I’m still having a lot of trouble getting it to work. Even when I do not press a single key, I am still getting large numbers for both correct and incorrect when looking at the data sheet.

Actually my previous code will add to incorrect every frame. Presumably you only want to add to incorrect once per routine which would need code in End Routine