| Reference | Downloads | Github

Same code in builder runs only for first 2 blocks


I’m building a programm in which participants select photos with the mouse (negative, positive or neutral) depending on instructions given to them at the beginning of each Block.
Now, on my excel sheet I have over a hundred possible combinations and I only want 20.
So I looked online and found the following code:

Tab Begin Experiment:
myCount = 0

Then in tab Begin Routine:
myCount = myCount + 1
if myCount > 19:
Trial.finished = True

I did use it and it worked perfectly… for the first two blocks.
In the Trial I have 5 random sequences
In Block 1 I specified in the code : if myCount > 19 because I want 20 trials, however all I get are 15.
Block 2 shows only one trial
Block 3 starts with the top right image in the center then once I click on the correct image it works fine for 2 trials then the programm exists automatically.

I tried:
Trial :
Tab Begin Experiment:
myCount = 0

Then in tab Begin Routine:
myCount = myCount + 1
if myCount > 4:
Essai.finished = True #there’s an indentation in there that won’t show in the post.

Block 1:
Tab Begin Experiment:
myCount = 5

Then in tab Begin Routine:
myCount = myCount + 1
if myCount > 23:
VisageN1.finished = True #that’s the name of the loop I’m trying to end

and so on… It didn’t work.
I also tried to add myCount=0 after VisageN1.finished, that didn’t work either. I tried adding myCount=0 in end of routine then in end of experiment. Didn’t work.
All blocks are constructed in the same manner with one excel sheet for each one.
No error message appears when the programm stops after 2 trials in Block 3.

The codes as they appear in Psychopy

All error messages I got during the day

A sample of the flow

A sample of my excel sheet

Last code lines in the coder

Code I used for the mouse

So there… I don’t know what to do and I haven’t got the slightest idea of what’s wrong…
Thanks in advance.

OS (e.g. Win10): windows 7 pro
PsychoPy version : V1 84.2

Hi. You’re basically doing the right thing but your code is fighting against itself. Notice how you set myCount to 0 at the the start of the experiment in one code component and then in another code component, you set it to 5?

There is only one “start of the experiment”. So if you inspect the code that Builder generates, you’ll find that there will be two lines, like this:

myCount = 0
myCount = 5

There is only one variable myCount, and it can only hold one value. So it will start the experiment with the value 5 (the last one assigned to it), which explains why you only get 15 trials in the first block.

The easiest solution would be to use different variable names for your counters for different parts of the experiment.

Worked like a charm. Thank you.