Error Message with JS but not Python in Pavlovia (Online)

URL of experiment: https://pavlovia.org/run/maisonallen/trial-1/html/

Description of the problem:
Hi!

I am trying to create a conditional loop where the participant must obtain > 0.99 of the answers correct in order to move on. I posted a question previously about the code component only working in PsychoPy and not online in Pavlovia and I was told to code in JS manually (Conditional Loop Works in PsychoPy but not on Pavlovia - #3 by dvbridges). I am able to run the experiment with the Python except I cannot break out of the loop, however when I upload to Pavlovia with the JS, it will upload into Pavlovia, but then immediately pops up with an error that reads:

Unfortunately we encountered an error:
ReferenceError: frameDur is not defined
Try to run the experiment again. If the error persists, contact the experiment designer.

Please let me know what I should do. I will also provide the JS code I have below. I am new to coding, so I appreciate any help.

Routine_1_C
BEGIN ROUTINE
var score = 0;

END ROUTINE
if (key_resp_6.corr) {
····score = score + 1;
}

End_Routine
END ROUTINE
if (score > 0.99) {
····break;
}



1 Like

Looks like your issue is because the JS did not compile properly. You may have seen an error in your console such as Failed to parse as JS by esprima. This error is because of the use of the break statement in the JS code. This should be allowed, but PsychoPy is not handling this. I will look into this and raise an issue on GitHub if needed. In the meantime, you can use a different command to either end your loop or routine. To end a routine is JS code, use continueRoutine = false;, and to end a loop currentLoop.finished = true;.

I will try those, thank you very much!

Hello,
I’m having a similar problem of getting an error when using a break statement and trying run it on Pavlovia. I tried using what you suggested above, but I get the following error: ERROR Line 518: Unexpected end of input.
This is the code I have:
respcorrs.append(resp.corr) # assumes your keyboard component is called “resp”

if len(respcorrs) >= minNrPractice:

respcorrsRecent = respcorrs[-considerNrTrials:]

respcorrsSum = sum(respcorrsRecent)  # only works if error=0 and correct=1

accuracy = float(respcorrsSum)/considerNrTrials

if accuracy > minAccuracy:
    break

Is there a way I can fix this so that it will work in JS and on Pavlovia?

Thanks,
Ellen