The first few stimuli kept repeating in the inner loop

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

I put 1 in the nReps in Loop 1 (the condition file has 200 items, and I want the experiment goes through all of them sequentially) and 11 in Loop 2 so that 11 stimuli in Loop 2 will be randomly presented.

I think this code I put in ‘trial_1’ works as after 10 items from trial_1, it moves on to trial_2 (loop 2)
myCount = 0
myCount = myCount + 1
if myCount%10==0 and myCount>0:
Loop1.finished = True

But I have no idea how to prevent loop 1 keeps repeating from item 1-10. It just does not go to item 11-20 and so on.

Hey, please take a look at the following example I created for you: (30.2 KB)

Loop1 goes from rows 0 to 8 (from the first spreadsheet), then Loop2 takes a random row from the second spreadsheet.
Then Loop2 goes from 9 to 17, and Loop2 takes another random row from the spreadsheet.
The random rows from the spreadsheet won’t repeat themselves.

Let me know if I understood you correctly.

This is an example of the way I implemented it:




I just noticed the conditions from the second spreadsheet have double the items. It shouldn’t matter for the principal of this method, but it will stop half way through the first spreadsheet.

1 Like

Thank you so much!! This design has definitely solved my problem! It ran perfectly on Psychopy

But when I wanted to run on Palvlovia, the experiment couldn’t be initiated and there was an uncaught ReferenceError: loop1Reps is not defined. Is it because the Python code does not successfully compile to the JS code?