.thisIndex will not update within loop

URL of experiment: shim_js [PsychoPy]

(I am piloting, so can provide a fresh link if this one expires)

Description of the problem:

I present a series of images via a loop with loopType set to random and file names for the images occupying a column in the conditions .csv file. I want to know the order in which the images were presented to subjects (i.e., save the index positions in the .csv file in the order in which they appear in the loop). I have been using ‘[LoopName].thisIndex’ to extract the index position of the current routine’s image in the conditions file and then adding it to an array. While using ‘[LoopName].thisIndex’ in the python portion of the custom code component works just fine locally, it does not work on the javascript side/ when I run the study on pavlovia. If I use console.log([LoopName].thisIndex), the same number (I am assuming the index position of the first image that is presented) is printed on every iteration of the loop (i.e., .thisIndex does not update within loop).

Things I have tried:

  1. From similar problems, mostly related to ‘trials.thisN’, some suggested adding a trialCounter, which I have done and has not solved the problem.
  2. I checked the crib sheet and in the “Don’t” and “Do” table, it states “All loops are referred to as “trials”. Use the custom loop name when referring to trialList. Use “trials” for other attributes.” So, instead of using ‘[LoopName].thisIndex’, I tried ‘trials.thisIndex’ but I got an error stating that ‘trials’ not defined.]

Am I approaching this incorrectly? Is there any/another way to extract the order that stimuli appear in a loop when loopType is set to random?

Thank you in advance for help with this,

Did you notice this all loops being referred to as trials was fixed in 2020.2 but .thisN broke at about the same time. However, I think it still saves to the data file. Have you checked?

The solution, if you need it, is to use a loop counter.

Begin Experiment
loopIdx = -1

Begin Routine

Thank you for your response!

Sorry, should have included this detail: [LoopName].thisIndex saves to the data file just fine! The finished .csv file contains this column. The problem is that I need to make use of these index positions in the next part of the experiment. Is there a way to access a column in the forming data file as the experiment is taking place?


No – hence my recommended workaround.

My apologies if I am misunderstanding but the suggested workaround leads to a column being added to the final data file counting the routines (equivalent to .thisTrialN or .thisN). But I need to extract the index position in the conditions .csv file of the currently presented stimulus (which is normally possible with .thisIndex). Is there any other known way to save the order in which stimuli appear in a random loop besides .thisIndex?

Sorry – my misunderstanding.

Begin Experiment

Begin Routine

I think I found a workaround!

It is possible to save, for and within the current routine, the $[ConditionsFileColumnName] being presented. For more explanation: I have attached two screenshots, one of my defining of the loop in the Builder, listing the single parameter in my conditions file: face_file (the header of a column holding pathnames for each image to be presented in the loop) and another screenshot in which I show the image component in the routine of this loop, where $face_file is the Image and is set every repeat. Within a routine, I can extract face_file and add it to an array in a js code component:

Begin Experiment
shuffled_facefiles = Array([total#ofimages);

Begin Routine
shuffled_facefiles[i] = face_file;

With this, I have been able the image file names in the order in which they appear in the loop.

Jinx! Thank you for your help. Much appreciated