Creating blocks with trials and a screen after each block

Hello everyone,
OS: Win10
PsychoPy version: v2022.2.5
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: I have designed an experiment and I want it to have 6 blocks with 12 trials each, and a screen that shows the subjects a message containing the number of blocks they have completed and the total points they have reached after the completion of each block (and ideally, also adding up the points of all the completed blocks).
This is the Builder view (you can see all the routines in the Routines window):


The experimental desing goes as follows: after the welcome & instructions screens, the subjects see a fixation cross, then the cue (that sets the reward condition - low or high - through its colour), then th ITI, and then the ‘Emotional_Stimuli’ routine appears. This routine contains 2 images of faces portraying emotional expressions. Subjects must choose which of them is more representative of the emotion. Then subjects must choose from within a list of options which emotion they think the pictures were showing. Depending on the reward condition and they answers, they get more or less points.
The ‘Initial_Routine’ contains a code component with:

import random, xlrd

#randomize seed
random.seed()

#input file
in_file = ‘Photos.xlsx’

#number of items to load
num_items = 12

The ‘Block_Progress’ routine also contains a code component, meant for the screen with the progress, but it did not work.

What did you try to make it work?: Firstly, regarding the blocks, I have all the routines and loops, but I do not know whether I have to copy these 6 times or if there is another easier/faster way. My experiment is an incentivized facial emotion recognition task. I have tried setting the nReps of the loops to 6, but it didn’t work. And I don’t know how to set the trials to be 12. I also have the code in the ‘Initial_Routine’.
Regarding the screen showing the progress, I tried adding the ‘Block_Porgress’ routine, and a code component in it. As for the code snippet to include in this component, I asked ChatGPT, but its answers were making my experiment crash for diverse reasons (i.e., it created variables that had not been defined before they were called).

What specifically went wrong when you tried that?: I am just not being able to do these things or they make the experiment crash (if I use the code provided by ChatGPT).

Thank you in advance,

Chema

Hello,

you have quite many question in one posting. So I try to tackle one after the other. But at first, I have a question? Do you plan to run the experiment online? If so, don’t import libraries. The Builder, which you seem to be using imports all libraries for which there are PsychoJS-counterparts.

The following toy-example show integers from 0 to 4 over five block. The block-number is show after the trials are over. Here the flow

I create the block-number in the code-component codeBlock. It is initalized in the Begin Experiment tab with

BlockNr= 99

In the Begin Routine tab, I assing the current loop-iteration to BlockNr. I add 1 because the counter starts with 0.

BlockNr = Blocks.thisN + 1

BlockNr is then show in the text-component textProgress.

I hope this helps.

Best wishes Jens

Thank you for your answer, Jens

I know there are many questions for just one post, but I thought that as they are related to each other and maybe be easily answered…

For startes, no, I am not planning to run the experiment online. The subjects will come to the lab.

I followed the steps you showed, but the experiment crashed under the following error:
NameError: name ‘Blocks’ is not defined (I saw it is in the line where ‘BlockNr = Blocks.thisN + 1’ appears)

Hello

in my example I have a loop called Blocks. You need to change Blocks to the loop-name that you are using.

Best wishes Jens

Hello, Jens,

Thanks to your clarification I was able to do it. But I’m seeing a message after each trial. I would like to show the subjects a message containing the number of blocks they have completed and the total points they have obtained after the completion of each block. But not after each trial.

I think I should start step by step. First of all, how do I create 6 blocks with what I have (what I showed in the screenshots of the builder)? Do I have to copy each routine 6 times or is there another, more practical, way?

Thank you in advance,

Chema

Hello,

you probably put the block-feedback at the wrong place. Look at my example. It has trials and blocks. The block-feedback is given when one block of trials is done. There is no need to create six blocks, just loop six times over the trial-loop.

Best wishes Jens

Thanks a lot, Jens!

That made it. So, the next part is: how do I set 12 trials for each block now?

Hello

You do not provide enough information to answer this question. Will you show the same or different stimuli on each trial? If you show different stimuli on each trial, how do you load them? If you load your stimuli using a condition file, the default is displays all rows of the condition file. The default is five repetitions of the whole condition fle. The Builder will show you the number of rows it has detected in a condition file. See the following example

graphic

This condition file has 23 rows, actually 24 row, but the first row contains the variable names (original, changed, flicker, object, semantik, dauer, picdur, maskdur). The loop runs once. Only rows 0:3 are used in this loop. The other rows are not displayed.

This is a very basic question. It might be worth looking into: Peirce, J. W., Hirst, R. J. & MacAskill, M. R. (2022). Building Experiments in PsychoPy. 2nd Edn London: Sage.

Best wishes Jens

Dear Jens,

I had a look at the book and I was able to answer all my requests. Thank you for your attention and recommendations!

Best,

Chema