Keep tracking of correct responses' score of an initial routine to END the experiment or continue in next routines

Hello,
I am using Psychopy 2020v.2.5, the builder view. I have a screening trial at the beginning of my experiment, in which I want to keep tracking of the number of correct responses by the end of a loop of six trials (rows) in a condition file with a corrAns for that screening. Now if the score was 5 correct out of 6 or more (e.g., 6/6), the participant should be able to move to the next routine in the experiment until the end of the experiment. On the other hand, if the score was 4 or less by the end of the loop, then the participant should not be able to move to the next routine in the experiment and instead he/she gets a ‘Thank you’ message and then exit the experiment.

How can I do that? Any help is appreciated.

Hi There,

You need to add a code component to your routine (custom>code) and use something along these lines:

Begin experiment tab:
Corr_count =0

End routine tab:

if resp.corr:
    Corr_count +=1

Then add a code component to the next (optional) routine (and any following routines that occur before your thankyou message) and type something like this:
Begin routine tab (or each frame if using online):

if Corr_count <5:
    continueRoutine = False
    name_of_current_loop.finished = true

Hope this helps,
Becca

I added the first two codes at the Begin experiment and End routine of the routine that has the loop of the trials, but now the experiment ended before starting the loop. However, no error message was displayed.

Aha yes that is because corr_count is initially 0 so the loop is ending before counting. Please could you share some screenshots of your current flow and code component ? that will make it easier to figure out what goes where.

Thanks,
Becca

I appreciate so much that you are welling to help me. Here are some screenshots.

Ok thank-you that is really helpful. So couple of changes.

  1. In ‘screening sounds’ remove the code in your ‘Begin routine’ tab (that needs to go somewhere else).

  2. Add a code component to the ‘now’ routine

3.In the begin routine tab of the code component in the ‘now’ routine enter:

if Corr_count < 5:
    continueRoutine = False

Note: You will want ‘score’ to read as ‘Corr_count’ (because that is the variable we are adding to).

Some background on the significance of these code snippets to help with use in future:

continueRoutine = False # this ends the routine you are currently in trials.finished = True # this breaks out of a loop IF WE ARE IN ONE

So, if you want to then skip all routines that follow ‘screening sounds’ if the participant has a low score, you will need to add a code component to every routine following ‘screening_sounds’ and in the ‘begin routine’ tab enter:

if Corr_count <5:
    continueRoutine = False
    trials.finished = True # but only use this line if you are in a loop

Note that you will need to substitute the word ‘trials’ in trials.finished for the name of the loop you are in (e.g. trainingblock2_correct_loop.finished = True)

Hope this helps,
Becca

It worked perfect locally. However, when I run it online, only when the correct responses were <5 then instead of just moving to the last ‘Thank you’ message and skipping all the routines in between, the first row in the conditions’ file in the next routine loop is run. Only the first stimulus with the feedback corresponded to it, then all other trials are skipped and the ‘Thank you’ message appear.
This is weird isn’t it? Why only when I run it online it work only partially. And why is it the first trial only run and the rest are skipped instead of skipping all the trials.
Could it be related to adding a code to “Each frame” instead of “Begin routine”?

Yes - try moving the code in the ‘begin routine’ to ‘each frame’ for running online

Becca

I moved all the codes to the ‘Each Frame’. It partially worked. That is, the first sound (incorr…_sound) [IN THE SCREENSHOT BELOW, THE FLOW] in the last routine, which should be skipped altogether, was played.
So, moving the codes to the ‘Each frame’ as if it shifted the skip to the right but not completely. I have no idea how to deal with that. In fact my actual experiment has additional routines after that sound screening initial routine. Would these codes help to skip more routines? I just tried it with that one routine to be skipped.
Thank you very much and I apologize for this complicated problem that I am introducing.

You don’t need to move all of the code to each frame. Only the code saying we are skipping this routine if the correct score has been reached. Please can you share the URL to your project Unable to download resource

yea I moved only that code. I don’t think I have credits yet that is why I don’t think I can have a URL in Pilot mode. I buy some credits and send you the URL.

Hello,
Here is the Url: https://pavlovia.org/run/gshejaeya/hvpt3/html/
Thank you very much.
Ghada

Hi,

This is a link to the experiment not the gitlab project, please follow the instructions on the link provided above to share your experiment files with us via pavlovia.org.

Thanks,
Becca

Oh Sorry. Okay I invited you.
Thank you so much

Hi, I just had a run of your task (nice task by the way!) - and this seemed to work OK, I was terrible at judging which was softest, so I was taken straight to the end message - can I confirm this is now working for you?

Thanks,
Becca

This part is supposed to check if the participant is wearing headphones or not during the experiment. So you didn’t hear the buzzer sound at the end? because you are not supposed to. The buzzer sound is part of the last routine loop (the incorrect loop).
and how did you fix it? because this will be the first part of a vey long experiment and I am afraid that the longer routines won’t be skipped properly.

So , I added these codes to the original experiment HVPT_b1 that I also invited you too. and I have same issue. Now the image of the first routine in the last loop in the flow is presented rather than skipped.

Hi There,

Please can I confirm if you are still having this issue? I can confirm that when I ran the task all routines up until the end message were skipped if I performed poorly in the sound_screening - which I think is what you needed?

Thanks,
Becca

I also get a 404 message if I try to access your second task, think ing you may have resolved the issue so been able to remove me :slight_smile:

Yes, the issue of skipping the following routines was solved using the codes you recommended. I appreciate your help very much. As for the buzzer sound that was not supposed to be heard from the last routine, I solved it by adding a silence sound file to the last routine. It is not the ideal solution but it worked.
Thank you again for your help :slight_smile:

fantastic to hear!