Randomly pick up an image from a big pool of images all belonging to a condition

Within the conditional statement try just doing

trials.finished=True

or

trials.finished=true

for JS.
They updated the way the end loops. See Loop.finished=true No longer working for details.