The first few stimuli kept repeating in the inner loop

I have 2 types of stimuli (i.e. Stimuli A and Stimuli B) for 2 decision tasks. There are 200 Stimuli A and 20 Stimuli B. I have made two loops so that 1 stimuli B (random) can appear after every 10 stimuli A (sequential). I added the code:
myCount = 0
myCount = myCount + 1
if myCount%10==0 and myCount>0:
Loop1.finished = True
However, the first 10 stimuli kept repeating without progressing to the next 10 stimuli. How can I fix the code so that the whole list of stimuli can be presented?

Can you show us the flow of your experiment?
I don’t understand the whole picture.


Thank you so much for your reply! I want to present 1 trial_2 item after every 10 trial_1 item (sequentially). But now only first 10 items kept repeating in the first loop. Is there any way to present the whole list in this design?

Can you please share the properties/settings of Loop1 and Loop2?

In Loop1, I add a code in the trial_1 so that the routine will continue after 10 stimuli:
myCount = 0
myCount = myCount + 1
if myCount%10==0 and myCount>0:
Loop1.finished = True

I see the problem.
The loop doesn’t have any indication to start from a row other than the first one.
Did you try modifying the Selected rows option?
For example, something like that might work:

# Selected rows (inside the Loop1 properties):
$Loop1.thisN + Loop2.thisN * 9

# Selected rows (inside the Loop2 properties):
$Loop2.thisN + Loop2.thisN * 2

You probably need to modify the nReps and change the calculation of the selected rows, but it should give you a solid direction to the solution.
Let me know if you need more help :slight_smile:

Thank you so much for your help!! Let me try to modify it now.

There is an error when I sync it to the palvolvia:
“TypeError: Cannot read properties of undefined (reading ‘thisN’)”

thisN seems does not work in palvlovia

On which version of PsychoPy are you working?
The same thing happened to another user today:


trials.thisN worked with 2022.2.4 which I have installed.

Best wishes Jens

I am using 2021.2.3 version of Psychopy. I used the latest version 2023.1.1 to build the experiment before, but it was unstable and caused some errors in palvlovia. The older version seems to be more promising.

Thank you so much, Jens! I will install the 2022.2.4 version.

1 Like

There is an easy workaround around it. I also mentioned it in the other thread:
What you can do is create a new variable that is equal to 0. Then each time the routine start/end, increase this variable by one. It works the same as thisN.

I used 2022.2.4 version but there is still an error in palvlovia TypeError: Cannot read properties of undefined (reading ‘thisN’)

Regarding creating a new variable, should I insert the code in trial_1? I am not sure how to work on it.

Hey @wakecarter , do you know if the thisN work on this version?

Yes. According to my crib sheet it works from 2021.2

I tried to put the string $Loop1.thisN + Loop2.thisN * 9 in ‘selected row’ option of Loop 1, but there was TypeError: Cannot read properties of undefined (reading ‘thisN’) in palvlovia. Does it mean that I did not define this variable in the JS code?

Loop1.thisN doesn’t have a value in the definition of Loop1

Thank you so much! My intended flow is:

Stimuli A: 0-9 (loop1)
Stimuli B: random 1 (loop2)
Stimuli A: 10-19 (loop1)
Stimuli B: random 1 (loop2)
Stimuli A: 20-29 (loop1)
Stimuli B: random 1 (loop2)

I have never tried to modify Selected rows options before, so I am not quite sure how I should modify to get what I want.

Have you put 3 reps for loop1?

Put 1 rep for loop1 and add an outer loop0 which sets the nReps for loop1