psychopy.org | Reference | Downloads | Github

Repeat loop if incorrect - JS

#1

Description of the problem:

I am trying to repeat a loop of training trials till everything has been correct. I created (as recommended in other posts) a nested loop structure and inserted a code component. Offline everything works well, but I am struggling with the transition in JS. I appreciate every help.

Py:
if not resp1.corr:
trials.finished = True

JS:
if not (resp1.corr){
trials.finished = true;
}

Thank you very much!

#2

I am no JS expert (I am still learning), but, if I am not mistaken, if not is not part of the JS syntax. Try:

if (! resp1.corr) {
      trials.finished = true;
}
#3
if (!resp1.corr){
    trials.finished = true;
}

There is not any not operator in JavaScript.

#4

Thank you very much for your suggestions. I implemented those changes, but it is still not working online.

Does anybody can tell me why it is not working? Thank you very much in advance!

#5

Is there a reason why your commands are different for python and JS?

py: trainings.finished
JS: trials.finished

#6

That was a mistake, but even when I fixed that, it does not work.

#7

You should provide a description of the experiment and .psyexp file so that the JS experts can take a look at it.

In any case, did you look at this?
I also seem to remember that loop termination was going to be implemented in PsychoPy 3.1.0. Did you try to update to that version?

#8

Hi @rob-linguistics13,

I am building a modified version of the stroop task. To begin with, participants will run some trials for training. This loop of training trials should run again and again, till everything has been correct, to make sure that every participant understood the logic of the task.

I am not sure, how to implement the code correctly. I just noted that the code above (If not…) does not work properly, because even when the participant answers everything correct, it does not skip the outerloop.

I created an example file:

example.psyexp (9.0 KB)

I appreciate any helpful suggestions!