Potential scope issue with getting and altering loops

URL of experiment: gitlab.pavlovia.org/kdoelling1919/uncertain-future.git

Description of the problem:
My intention is to have a set of training blocks which end when the participant has gotten more than 75% of trials correct in the last block. It starts with an easy block which the participants have to meet the threshold and then when this is accomplished a slightly harder training session with the same threshold. Then it should cut out of pracBlocks and move to the main experiment.

How to implement:
I have a loop pracBlocks with no condition file and nReps set to an arbitrarily high number (99) which deals with the block iteration and an inner loop practices which iterates through trials. A block counter pracBlockNum which increases when the participant gets over the threshold. If pracBlockNum is more than 0, it chooses text and sound wav files for the harder session, otherwise easy session. After the practices loop (outside of this inner loop), i have an endPractice routine with the following code component in Begin Routine

percCorrect = corr_responses.reduce((acc, it) => acc + it)/corr_responses.length;
if ((percCorrect >= 0.75)) {
    endPracText = `You got ${(percCorrect * 100)}% of the previous blocks trials correct and can therefore move on! Press any button to continue.`;
    if ((pracBlockNum !== 0)) {
        pracBlocks.finished = true;
    }
    pracBlockNum += 1;
} else {
    endPracText = `You got less than 75% correct. Please try this training block again.`;
}

endPracText is used in a text component in the same routine.

Weird result:
What actually happens is that the first easy session works as expected. But the second harder session continues to loop over and over.

I used the firefox console to try to debug. What I find is that the code does alter pracBlocks.finished to true but when the program hits the EndLoopIteration function. The pracBlocks object it operates on is totally different from the one I was working with. pracBlocks.finished is false and the index variables (e.g. .thisIndex, .thisRepN, etc) are up to date whereas when operating in my code component space, these never seemed to update correctly.

I am quite sure that I am missing something obvious having to do with the scope of the pracBlocks variable but I can’t for the life of me figure out what. Any help with this would be greatly appreciated.

Based on my reading of the discourse I tried these things but no luck.

  1. Setting isTrials to true in pracBlocks Builder gui doesn’t change this.
  2. this technique
  3. Changing pracBlocks.finished = true to currentLoop.finished = true

Version info:
Psychopy Builder: v2020.1.2
Psychojs platform: latest
Browser running: Firefox 75.0

Try trials.finished = true. See here: Loop.finished=true No longer working

Yup… That fixed it. I definitely assumed that trials was the Loops Name in that example.

I have a different loop whose name actually is trials. Do I need to change it?

Also, will trials.finished = true also work in psychopy?

If it’s working now, then no, because if there was an assignment conflict then trials.finished wouldn’t have worked in the first place. It might be a good idea for clarity’s sake if anyone might want to build on your code in the future, though.

I think so but I’m not 100% sure.

thanks for your help!