trials.thisN with continue routine not working

I am using code to stop a routine after a number of trials have been completed.

I have tried all of the following methods

if trials.thisN == 5:
   continueRoutine = False

I have also tried adding a counter and having counter += 1 in end routine and then

if trials.thisN == counter:
   continueRoutine = False

I’m sure I’ve used something similar in the past, but I do recall thisN didn’t work for a while and was wondering if there was an issue or if I have forgotten something?

I did also try to use print(counter) and print(trials.thisN) but the runner is clogged up with other things I’m not really interested in currently.

Which tab is your code in?

For the first one it’s in begin routine

For the second:
counter= 0 in begin experiment
main code in begin routine
counter +=1 in end routine

Do you want to just skip the routine or break out of the loop?

To break out of the loop I would put code in End Routine

if trials.thisN == 4:
   trials.finished = True

To check whether trials.thisN is working use


thisN is working, I have managed to find the print out. However neither ending the routine nor ending the trials are working alonside it.

I currently has it sent to if trials.thisN ==1 for speed, but it continues and I get a print of thisN 2 etc

What version of PsychoPy are you using?

What does your flow look like? Do you just have one loop called trials?


There are two other loops around other routines called trials_2 and trials_3

I managed to fix it. They were using trials_DMM, changing this to trials_4 instead has fixed the issue. It seems that trials.thisN doesn’t like anything other than numbers after “trials”