psychopy.org | Reference | Downloads | Github

Online study with loops not progressing correctly

Hi. I have a study design with nested loops. There’s a code component (written in both python and JS) saying that the inner loop should end upon a correct response (meaning, if the response is wrong, participants will see the same stimulus again until they respond correctly). This design works correctly in PsychoPy, but not online.

On Pavlovia, you just see the same (first) stimulus over and over. I’m attaching the PsychoPy file, in case that helps. I couldn’t figure out how to attach the JS file, which I imagine would be more helpful.

Thank you so much!

game_online12.psyexp (96.5 KB)

Hi. I have the exactly same problem. I put below code in the end routine tab of the code component

if (key_resp_2.corr == 1) {
    innertrials_1.finished = true;
} else {
    innertrials_1.finished = false;
}

However, it doesn’t work…
Let’s wait someone’s answer.

Hi, we are currently looking into this, thank you for your patience.

Hi, did anyone ever figure this out? This is the exact problem I’m having with my study at the moment. I’ve looked at about 6 other posts about ending loops and still have not found a solution.

@Leah107, yes for online studies you have to use trials.finished=true; to end any loop.

@dvbridges I changed the names of my loops to “trials” as you suggested but my experiment still gets stuck on the inner loop in Pavlovia. In my experiment participants need to select the correct translation for 60 different words. My inner loop should end if the answer is correct and should repeat if the answer is incorrect (which then repeats the same word until the correct answer is selected). Once participants have correctly answered all 60 words, the outer loop ends (which ends the trial routine). Currently the inner loop does not end, even when the answer is correct.

This is my experiment in builder:

In my TRIAL CODE I have number_correct = 0 in Begin experiment and the following in End routine:

if(key_resp.corr == 1):
number_correct = number_correct + 1
trials.finished=true
This was previously LoopInner.finished

if(number_correct >= 60):
trials.finished=true
This was previously LoopTrial.finished

In my FEEDBACK CODE I have this in Begin routine:
if key_resp.corr:
msg=""
else:
msg=“INCORRECT”

Any assistance would be appreciated!

Isn’t it True not true for the Python?

Apologies @Leah107, I should have been more descriptive. In Python, you can use the actual loop name to end loops:

if(key_resp.corr == 1):
    number_correct = number_correct + 1
    LoopInner.finished=True

As Wakecarter mentioned, you use titlecase for True in Python code, but lowercase true for JavaScript. The issue ending loops online will occur when you use auto-translate to create the JavaScript translation of the code. In JavaScript, you have to manually edit the translated code to use “trials.finished=true;” for ending any loop, rather than using the actual loop name. If your loops are not ending in Python, then there may be an issue with your conditional statement not being satisfied.

@wakecarter @dvbridges When I built the experiment in PsychoPy, my original code was this:

Then I manually changed the code to this so that I could run it in Pavlovia (still not working):

I am very new to PsychoPy so please let me know if I am doing anything wrong!

If it helps, I am attaching my PsychoPy experiment: Vocabulary Familiarization Task_FINAL.psyexp (36.7 KB)

Thanks for the screen dump. The panel on the left is Python, and the JS equivalent is on the right. In the left panel, use the actual loop name e.g., LoopTrial, and use auto-translate (code type “auto->js”~). Then, you need to change the code components code type to “both”, and in the right JS panel, change the loop ending code to trials.finished=true;

@dvbridges Thank you for explaining that. I followed your instructions exactly and it continues to be stuck on the inner loop when run in Pavlovia. I’m not sure where to go from here. I’ve read so many other posts about this issue, but can’t seem to figure it out.

Your second trials.finished is referring to the outer loop, isn’t it? That’s not going to work there. Try adding a routine outside the inner loop with that code.

@wakecarter I did what you suggested (images below) but the inner loop still is not ending properly. I wonder if there is a problem or something missing with my coding.

Screen Shot 2020-06-14 at 2.14.39 PM

This is what I copied into the End Routine for Trial2 code:
Screen Shot 2020-06-14 at 2.15.21 PM

If the problem seems to be that key_resp.corr==1 is never being evaluated as correct then it could be that you should delete ==1 or replace it with ==‘1’

Can you tell from the feedback routine whether the issue is that the loop isn’t broken or the answer is never correct?

For the most part, the feedback routine seems to work. When I select an incorrect answer, the appropriate message (“INCORRECT”) is displayed on the screen. Most times when I select the correct answer, no message appears on the screen, as it should. However, at times when I select the correct answer, the “INCORRECT” message appears only for a brief moment, as if the experiment thought it was incorrect, but then realized it wasn’t.

Here’s a potentially silly question: How can I be sure my PsychoPy experiment is successfully updating in Pavlovia? I keep pressing the “Sync with online project” button in PsychoPy assuming that was updating the experiment online. However, I just removed the feedback routine to see if that was somehow messing it up, and when I piloted the experiment online, the feedback routine was still there. Have I been doing something wrong?

This issue was the bane of my life. I started editing a text component on every upload with the current date and time so I could check whether the experiment I was testing was the latest one. The relevant part of my crib sheet is:

Use Developer Tools (Ctl-Shift-I in Windows/Chrome, Cmd-Opt-J in Mac/Chrome, F12 in IE/Edge, Ctrl-Shift-J in Windows/Safari, Ctrl-Opt-J in Mac/Safari) to view errors via the browser console if you aren’t getting sufficient information from PsychoPy. You can add print(var) (which translates to console.log(var); ) to check the value of a variable var at a particular point.

If Pavlovia refuses to run the latest upload of your experiment, disable the cache via Network conditions in the browser console. You may also need to clear the cache when you first set this (using Ctl-F5 or equivalent).

It works online now! @wakecarter Thank you so much for your help! First I disabled the cache via Network conditions, but that didn’t work. For some reason the changes I was making in PsychoPy desktop were still not updating online. So I created a new project, copying the exact design of my previous experiment (including the additional routine outside the inner loop), and when I synced that new experiment, it was updating correctly (a dialogue box telling me how many changes were being made appeared every time I synced it, which had never appeared before).