| Reference | Downloads | Github

Conditional Loop not working online (working on psychopy 2020.1)

URL of experiment: Sign in · GitLab

Description of the problem: Hi everyone! I’m having an issue with running an experiment online on Pavlovia. It works on the builder (version 2020.1).

The issue is: It is a task-switching paradigm and, for the practice trial, the participants have to repeat the practice in case they made less than 9 correct trials out of 12. I created a counter for the correct response in the practice trial in a code component and the code looks like this:

Begin Routine:

’ if practice_shape.thisN == 0:
number_correct = 0 ’

where practice_shape is the name of the loop (which also contains a fixation cross and a feedback for correct response that prints “correct” or “Incorrect”)

and in the end routine:
’ if prac_resp.corr:
number_correct = number_correct + 1 ’

where prac_resp is the keyboard component

then, in the outer loop I’ve created a routine called “end_prac” with a code component:

Begin routine:
’ if number_correct > 9:
practice_back.finished = True
skipThisTrial = True
continueRoutine = False ’

This allows participants that make more than 3 mistakes to go back and redo the practice, and those who make more than 9 correct to not begin the routine and jump to the next on.

This works on psychopy builder but not online.

I’ve spent some time reading previous topics and I’ve tried different ways but it still does not work online.

Can anyone help? :slight_smile:

Thank you so much,

you said “This works on psychopy builder but not online.” what errors are you seeing in your browser console?

Hi Xinzuh-Fang, thank you for your response. I attach here the screenshot from the developer console. It does not give any error. It work but it doesn’t read my code component, basically it doesn’t break the loop with my conditions, it goes on the same loop.

Hi Carloa,

The problem might be that you refer to a custom loop name. This is fine on the python side of things (which is why it works fine in your psychopy) but on the JS side you might want to change this to be trials.finished.

See this useful sheet -

Hopefully that works :slight_smile:

Nice Doc! I think it can help lots of people (including me someday). I recommend developers adding it to Please help making this forum great for everybody! . Thanks for sharing!

1 Like

Hi Ipxrh6,

Thank you so much. This solved the issue. In the builder putting in the Py side : ’ trials.finished ’ is not ok because it gives an error : ‘names trials not defined’ , but it works perfectly online now. It’s better to translate this manually to JS in order to run it in both platforms.

Thank you again!!


1 Like

Its awesome right! Kudos to the creators of it !!

1 Like

Fab, pleased this solved the issue. One thing to watch out for in future is to check the auto translate doesn’t reset your “trials.finished” back to the custom loop name whilst you are editing (it can do this because the Py > JS" is the default). So if you make edits in your local copy double check that before syncing it back to Pavlovia.

This is also an issue, because at times the code in the jc side goes back to the autotranslation. Do you know if there’s a way to put “both” or just “js” as default instead of “auto-js” ? thanks!

I am not sure if there is a way to change the default translation setting, perhaps that is in the future pipeline for PsychoPy preferences ( @TParsons might Have more insight there ) - for now if the custom trials is the only manual change you make you might just need to check that before uploading each time.

Hi all,

Yes, the code editor reverting to Auto-JS is something we’ve fixed in the next release! A few people had reported it.

1 Like

As per my crib sheet, you can change this. However, it’s a double-edged sword.

N. B. See How to set Default Code Type to avoid frustration. I would also recommend having code that needs to be manually edited in a separate code component so that you can continue to use the auto translate for new code. Default Code Type changes the whole component, not just the current tab.