Exiting an online experiment early

URL of experiment: The experiment is not public and is currently in piloting mode.

Description of the problem: The task is a stroop. The participant must complete a practice round of 20 trials with at least 50% correct responses otherwise they have to complete another round of 20 practice trials. If at the end of the second round of practice trials the correct responses are still below 50% then the experiment ends by skipping the experimental trials and going straight to the goodbye message. Everything works as it should in builder, but when uploaded to Pavlovia the experiment fails to skip the experimental trials.

I have a code component in the practice feedback:


Begin experiment (Python):
msg = ''
corrCount = 0
totalCount = 0
stopExp = 0

Begin experient (Javascript):
msg = "";
corrCount = 0;
totalCount = 0;
stopExp = 0;

Begin Routine (Python):
totalCount=totalCount+1
if PracticeResponse.corr == 1:
    msg = "Correct!"
    corrCount=corrCount+1
elif PracticeResponse.rt == []:
    msg = "Trop Lent!"
elif PracticeResponse.corr == 0:
    msg = "Erreur!"

if totalCount==20:
    if corrCount/totalCount >= 0.5:
        PracticeLoop.finished = True

Begin Routine (Javascript):
totalCount = (totalCount + 1);
if ((PracticeResponse.corr === 1)) {
    msg = "Correct!";
    corrCount = (corrCount + 1);
} else {
    if ((PracticeResponse.corr === 0) && (PracticeResponse.rt > 0)) {
        msg = "Erreur!";
    } else {
            msg = "Trop Lent!!";
    }
}

if (totalCount == 20) {
    if ((corrCount/totalCount) >= 0.5) {
        PracticeLoop.finished = True;
    }
}

End Routine (Python):
if totalCount==40:
    if corrCount/totalCount < 0.5:
        stopExp = 1
        PracticeLoop.finished = True
        Boards.finished = True
        
    else:
        totalCount=0

End Routine (Javascript):
if (totalCount == 40) {
    if ((corrCount/totalCount) < 0.5) {
        stopExp = 1;
        PracticeLoop.finished = true;
        Boards.finished = true;
    } else {
        totalCount = 0;
    }
}

The loop that contains the practice trials is called “PracticeLoop” and is nested within the larger loop called “Boards” which also contains the trial loop which is called “TrialLoop”. The goodbye screen exists outside of the Boards loop.

If I include the statment: TrialLoop.finished = True (Python)
TrialLoop.finished = true; (Javascript)
in the End Routine the experiment crashes saying that the TrialLoop is not initiated.

How can I get the experiment to exit the Boards loop online?

Thank you for any help you can give me.

Anthony

Hi There,

I formatted your code block to make this a bit easier to read. Please could you share a copy of your .psyexp file to make this easier to visualise?

Thanks,
Becca

Hello Becca,

Here is the experiment file.

Thanks for your help.

AnthonyStroopV14.psyexp (54.2 KB)

Hi There,

Thanks for sharing these! OK so here is how I normally do this in pavlovia and it works.

  1. make an arbirtary variable to say if an experiment should end

“Begin experiment tab”
endTask = False

  1. when you set your loops to finish, also set this variable to be true, in your case:
if totalCount==40:
    if corrCount/totalCount < 0.5:
        stopExp = 1
        PracticeLoop.finished = True
        #TrialLoop.finished = True #<- This line threw an error for me locally - because you weren't yet inside your trial loop when it is called
        Boards.finished = True
        endTask = True
  1. In all following routines, add a code component and in the “eachFrame” tab (locally “beginRoutine” tab would be fine but online I find “eachFrame” is needed for some functions) write:
if endTask:
    continueRoutine = False
    nameOfCurrentLoop.finished = True

This is a common question, so I mocked up a demo similar to your task here Pavlovia

Hope this helps,
Becca

1 Like

Thank you Becca, that did the trick.

Anthony