Cannot exit loop in online Pavlovia (Using JS code component)

Hi! I was having a similar issue that I have solved (mostly). Hopefully this will be helpful to others.

I have a loop of trials, and wanted to randomly select 18 rows from a excel list of 216 rows. I tried entering $random(18)*215 into the “Selected Rows” box in the trial loop, which worked in the builder offine, but not in Pavlovia. I tried the recommendations in this thread and a couple of others: https://github.com/psychopy/psychojs/issues/68# and Loop.finished=true No longer working which again worked in the builder, but neither worked online.

Then I found this old thread: My code component doesn't work in the online experiment, though works fine on desktop psychopy version

practrials is the name of my loop

I initialised a counter in the *Begin Experiment tab:
myCount = 0
that counts the trials in the *Begin Routine tab:
myCount = myCount + 1
Then in the *End Routine tab:

if myCount > 18:
    practrials.finished = True
    skipThisTrial = True
    continueRoutine = False 
else:
    practrials.finished = False
    skipThisTrial = False
    continueRoutine = True

And finally in the *Each Frame tab:

if practrials.finished == True: 
    continueRoutine = False
else:
    continueRoutine = True 

It is probably an inelegant solution, and some of it might be redundant. But it does exit the loop after 18 trials, running online on Pavlovia. One remaining issue is that in my datafile it still includes all 216 rows of my conditions file, so if anyone has any ideas how to fix that please let me know.

I’m new to these forums so apologies if this is unclear.