Count blocks and display

OS Win11
PsychoPy version v2022.2.5
**Standard Standalone? y

I am using the builder. I have a break in blocks. I’d like to count the blocks and display as a message to participants how many blocks they’ve completed.

In a routine, I’ve added the following code in the ‘Before Experiment’ tab:

block_count = 0;

I’ve then added the following in the ‘Begin Routine’ tab:

block_count = block_count + 1;

if block_count == 1:
msg_1 = ‘You completed %.0f block out of 5.\n \n Take a short break. \n \n Press X when you are ready to continue.’%(block_count)

elif 1 < block_count >= 4:
msg_1 = ‘You completed %.0f blocksout of 5.\n \n Take a short break. \n \n Press X when you are ready to continue.’ %(block_count)

elif block_count ==5:
msg_1 = ‘You completed the experiment - well done! \n \n let the experimenter know you have finished’

in the text component I’ve added ‘$msg_1’.

The block_count doesn’t seem to count and I only ever get the message for “if block_count == 1”

Any help much appreciated.
Likely something small and stupid.

This construction may not work. Since at this point in the clause you already know that block_count != 1 you could put

elif block_count < 5:

I realise that you’ve actually put if block_count >= 4 but I’m guessing this was a mistake.

If you want a double comparison, try:

if 1 < block_count and block_count <= 4:
1 Like

Thanks - you’ve identified my idiocy twice now.

It worked when I switched to:

Thanks for taking the time to help me out!