Trials.finished = true doesn't work

I have an experiment in which participants are asked to give a key response ‘1’, ‘2’, or ‘3’, based on their response to a question.
For those who press 1 or 2 I’d like the loop to end. And for those who press 3 it should continue on to the next page, where a message comes up that they are ineligible and to press space to exit.
I have this working on psychopy, but on pavlovia I can’t figure it out.

I have a loop with 2 routines
Screen Shot 2022-09-01 at 5.49.18 pm

The code in the first routine looks like this


I want it to record their response, and for those who respond 1 or 2 for the loop to end. I’ve set it up using trials.finished = true as I’ve read that it cannot be the name of the loop itself, and continueRoutine = false.

It should ideally then move to the next routine where I have coded:


in which those who respond with 1 or 2 should skip this routine and move on with the experiment. Then for those who responded with 3 should advance to this piece of code

The error message I get on pavlovia is

Does anyone know a fix to this? I’d really appreciate the help!

Does this help you? Loop.finished=true No longer working - #42 by elizagoldstein

In the latest versions (i.e. since 2020.2), this has been working online the same as offline. Your issue is that you have used trials.finished in your JS instead of visionloop.finished.

Hi there,
This what was originally in my code. I had visionloop.finished and it returned the same message, which is why after looking through the forums i tried trials.finished.
I have since fiddled around and created another solution!
Thanks for the help though!

@emily01

Hi Emily,

I have encountered the same problem where ‘trials.finished=true’ in JS does not work with online experiments. Could you please help me with the another solution that you mentioned above?

Thanks!

Please could you specify your version of PsychoPy and confirm the name of your loop and the error message you get?

v2021.2.3

I am trying to break out of the ‘pracLoop1’ if the %acc is 70 on a total of 24 trials. If not, the participant is redirected back to the practice and the max practice rounds = 3.

This is the error message when I run it on pavlovia:

image

@wakecarter

Please see the JS code in ‘face_pracfeedback_2’ routine:

Begin experiment:
//
ncorr1 = 0
eachResp = 0
varmsg1 = “”
PLoopTally = 0;
//

Begin routine:
//
for (eachResp=0; eachResp<psychoJS.experiment._trialsData.length; eachResp++)
{
if (‘practice_resp1.corr’ in psychoJS.experiment._trialsData[eachResp]) {
ncorr1 += psychoJS.experiment._trialsData[eachResp][‘practice_resp1.corr’];
}
}

if (PLoopTally <= 3)
{
varmsg1 = ‘Well done! Redirecting to the test trials.’;
trials.finished = true;
} else if (ncorr1 >= 17) {
varmsg1 = ‘Well done! Redirecting to the test trials.’;
trials.finished = true;
} else {
varmsg1 = ‘Your accuracy is low. Let us practice that one more time! Redirecting to the practice trials.’;
trials.finished = false;
PLoopTally = PLoopTally + 1;
ncorr1 = 0;
}
//

The same code was working online with a previous version of psychopy.

There used to be a bug in the online version which forced you to refer to all loops as trials. Since that has since been fixed, you need to use the appropriate loop name, e.g. practice_rounds1.finished

@wakecarter
The error message has disappeared now, but now the feedback text displays ‘Hello World’ instead of the intended message. Is there a bug with the code?

Have you put varmsg1 = something somewhere outside of your conditional clauses?

@wakecarter

Not that I can identify. Please see the below code for reference:

image

I see s syntax error in the ‘Begin experiment’ tab when it is set to Auto>JS. I am not able to pin point the error though.

The syntax error is because you have put JS code in the Python Window. I would highly recommend programming primarily in Python (with the Auto translate switched on) and use Both or JS only components only when necessary.

https://psychopy.org/online/psychoJSCodingDebugging.html

I got the same problem in psychopy v2022.1.4. It worked well in python but not in psychojs version.

Here is the experiment structure

And here is the code I used to terminate the task_trials loop (custom code under fixation1 routine).

Here is the local debug console output. It seems that task_trials.finished is undefined before I assign it.

Can anyone give some suggestion? Thank you!

Why do you think it isn’t working? What happens after it becomes true? From what I can see of your screenshot there is an unrelated error.

I want to terminate the task_trials loop at the 4th trial (if task_trials.thisTrialN == 3) in the first repetition of practice_formal loop (if practice_formal.thisRepN == 0).

Although the code execute task_trials.finished = True, the program still goes to the next routine (show_player), which trigger the unrelated error.

The code runs well in local but not in the online version.