| Reference | Downloads | Github

RT store format; loops randomization;

Hi everybody,

I’m using psychopy builder to build a lexical decision task (working on OS X El capitan 10.11.6; psychopy version 1.82.01, Standard Standalone version).

I’m trying to do two things without success at the moment:
–i’d like that psychopy stores reaction times in a milliseconds format and not in a second one (so if the time stored is “0,322961” I’d like that psychopy stores it in the format “322,961”);

–During an experimental session, a subject responds to three blocks (loops) of stimuli (48 stimuli for each block). Each stimulus consists in a pair of words presented sequentially (with a blank space between them) where only the second word must be responded (prime word and target word). The subject takes a short break (simple routine) after the first and the second block and he is able to push the space bar to finish the break starting the next block of stimuli. In spite stimuli in each block are presented in a sequential order, I’d like to counterbalance the presentation of the blocks randomizing the sequence (for example in a experimental session a subject could randomly see one of these sequences: “block1-break-block2-break-block3”, “block2-break-block1-break-block3”, “block3-break-block2-break-block1”, “block3-break-block1-break-block2”, “block2-break-block3-break-block1”, “block1-break-block3-break-block2”).
I have created 3 files for each loop-block (conditionsB1,conditionsB2, conditionsB3). In each file condition i have the parameters: itemnumber, primeword, targetword, corrAns.
I’ve tried to make a loop which includes all the three block-loops, and then selecting looptype=random, but it didn’t work.

Could you please help me with these two problems?
In these screenshots you can see where i’m stuck:


I’m allowed to post only two screenshots, the third consists in the third loop (equal to the others) and a final routine which says to the subject that the session is complete.

thank you for all your answers,

I increased your user trust level, could you try to include the third picture again? :slight_smile:

here’s the third one:

Will answer each of these questions separately (ideally each different question should be in its own topic):

PsychoPy will automatically store the reaction time in seconds but if it is important to you, you could add another variable that is converted to milliseconds. e.g. insert a code component, and in its “End routine” tab, put something like this:

 thisExp.addData('RT_in_ms', key_respB3.rt * 1000)

What you should probably do here is delete your second and third loops. Then insert another loop surrounding your trials loop. This outer loop could be called, say, blocks. The blocks loop should be set to random, and linked to a very simple conditions file that just contains the names of the existing conditions files, e.g:


Then in the inner trials loop, just put this variable name in the ‘Conditions’ field:


i.e. the outer blocks loop will select a new condition file randomly on each of its three iterations. The inner trials loop will then connect to a new conditions file on each of the three times it runs.

Each loop should have an nReps value of 1, which will yield three blocks of 48 trials.

NB this technique randomises the block order across subjects. A slightly different approach would be required if strict counterbalancing across subjects is needed.


Hi Michael,
All of your suggestions work! I’ve really appreciated your help…thank you so much!

PS and yes sorry for the two topics in one question! This was my first post and I’ll read again the community guidelines :wink:


Hi all,

I’m working on a similar script, and I’d be interested in knowing on how to perform strict counterbalancing across subjects.

Thank you!

Above we used a sort of “meta conditions file” to list the names of the actual conditions file to be used on each loop:


To get balancing, one of the easiest approaches is to create as many of these meta files as you need to cover the various combinations, e.g. another like this:


and so on. Each of those files will have its own filename (e.g. meta01.csv, meta02.csv, etc). What you should do is add a variable to the initial dialog box that appears when the Experiment runs (where you enter the subject code, etc). Call it say meta_conditions and enter what file you want to use on this run of the experiment (e.g. meta01.csv).

Then in that outer loop dialog, switch it from being a random loop to being in a fixed order, so you get the exact order you specified in the selected file. In the condition file field, don’t use a specific file name, but use the variable $meta_conditions.

Clear as mud?

Great, that works! thanks!

I have two follow up questions on the same topic.

  1. Within blocks I set up a routine that tells subjects that they can take a break between lists before starting again. I would like to let them know how many blocks are left. How can I do that?

  2. As of now, the break routine appears after the 5th block too. How can I tell the script to skip that routine when it is the last block and jump directly to the final routine?

Many thanks!

Builder loops are representations of 'TrialHandler` objects, which have a number of useful attributes to keep track of the current and total number of trials, as listed here:

So for example, you could put something like this in a text field:

$'Number of blocks remaining: ' + str(your_block_loop_name.nRemaining) 

And similarly, to skip a feedback trial, you could do something like this in a code component’s Begin routine tab:

if your_block_loop_name.nRemaining == 0:
    continueRoutine = False

Many thanks for your reply! One question:

When you say your_block_loop_name, which loop are you referring to? As you suggested above, I have two loops one inside the other - which one should I put there? I guess I’ll need to refer to the outer one, right?

Hi Roberto, I was giving a generic response. Try it and see what works in your particular situation.

So, I first tried to put $'Number of blocks remaining: ' + str(your_block_loop_name.nRemaining) when I initialize the component at beginning of the experiment, but it couldn’t see your_block_loop_name as it is defined later in the code.

I then tried to put it in the routine itself, later in the script:

text_field.text = text_field.text + "Number of blocks remaining: " + str(your_block_loop_name.nRemaining)

This works, but in this way a string "Number of blocks remaining: " + str(your_block_loop_name.nRemaining) would be incrementally added at the end of each block. How can I fix this?