Block and trials loop with complex stimuli configuration

Hello everybody. I am working on some experiments and I have some troubles to manage the loops around trials and condition. I did look at http://www.psychopy.org/builder/blocksCounterbalance.html
It does work for some of the simpler tasks I have, but it does not work for a couple of tasks in which a lot of the experimental features (like color, shapes and position) have to change time to time.
Specifically in a task I have the following things happening: a cue (saying which task the subject needs to perform), then there is a grid and a bunch of squares appearing in certain positions two at the time for 1 sec (total=4 seconds). At the end two grids are presented. One representing the sum on the squares seen before one with a mistake in the position of the squares. (then I have a jittered ITI, but I was able to manage it)

  1. In the WM condition the subject has to answer to which one between the two presented grids is the sum of the squares seen before
  2. in the control condition the subject have to say if a blue square (target) did appear or not during the trial.

I tried to follow the link above, so I have just one trial loop having $conds (which is a variable in the more external loop excel file) as condition. Then I have the external loops, having in the conds column the hyperlinks to my condition excel files. In the WM conditions I just Hyde the target using the background colours and so for the answer). So exactly as in the example I have an internal loop “trial” and an external one “condition”.

The experiment does work just if the two conditions excel files have just one row.

The squares positions and the target position must change necessarily for each trial. If I create a list of plausible positions it keeps looping for ever on the trials until it did not read all the excel file, so it does not switch between a condition and another.
I tried to program the two condition excel files to randomize the positions in order to have just a row but it won’t update automatically, so basically by having just one row I am able to run the experiment and randomize my two conditions between them but if I do so I just can it shows the same two configurations of stimuli (one for the control and one for the WM) for ever, so I can not randomize between my configurations.

Any suggestions about how to overcome that issue? I am ok in creating a list of positions if needed, but I do not know how to say Psychopy to read a row at the time. I have another task (Tower of London) which it is also more complex since the stimuli configuration can not be just random, but must be conditional to some task rules, so in that case the use of lists of specific configuration is mandatory for me.

Hi Barbara, the description here is a bit hard to follow. It might be useful if post some screen shots of your flow panel, the loop dialog boxes, and some content of your conditions files, and link your description to the actual names of the things shown in the screenshots.

Hi Micheal, sorry I was not clear. It is quite hard for me to describe things which are quite abstract. I hope that screen shots help.
As you see I have a complex routine ( called WM) with a bunch of shapes appearing at different timing




In the experimental condition the subject have to remember the position of the squares comparing with two different configuration shown. In the control condition the subject have to detect the presence of a target (called ‘Target’) that is a blue square among other squares which are black.

Following the instruction here http://www.psychopy.org/builder/blocksCounterbalance.html
I did not create two separate routines for the experimental and the control condition. Instead I have create just one routine applying on both (in the experimental condition the target is just being hidden overlapping on the experimental squares which are of the same color). Here my routines and my loops.


The cue tell the subject which task (control or experiment) it needs to perform. The internal loop called trials has as condition not an excel file but a column on the excel file called by the external loop (Condition)

Here the external loop ‘Condition’

and here the excel file condition_WM
59
the column “conds” contains the hyperlink to my two excel files having the information about the positions of my squares and my target. The cue_text column contains the text for the cue.
Now as explained above I have some troubles in having these loops working. The experiment works totally fine if my two conditions excel files have just one row each i.e. the experiment starts with instruction, then there is the cue, the experiment is finely shown, and when the loop is completed it starts again with another condition. Matter of fact I need my trials be different between them (i.e. my squares changing positions every time they are shown to the participant). I tried to have the excel file doing the work of randomizing the positions in just one row, but it won’t update while the experiment is running, so it is not working. So I can not use excel files for the two conditions that have just a row, but I need at least 20 rows for subjects containing the different positions configuration to remember. Now if I put 20 rows in my excel file, when a trial starts it continue looping until the end of the excel file and do not switch at the end of the trial from a condition to another as it should do. I guess I should act on the raw level for the trials loop, but I am not certain about how? Should I use a code telling Psychopy to end the trial every time the routine is finished. If yes how it should be written and where to put it?

But:

So it sounds like you aren’t really counterbalancing blocks of trials (i.e. the two tasks), but actually want to switch tasks from one trial to the next? (i.e. it is very important to precisely describe your design, as this can completely change the way it gets implemented…

If so, it it important that the task alternates from trial to trial (i.e. add/find/add/find/…, or could it vary randomly from trial to trial (add/add/find/add/find/find/…)?

Hello Micheal. The sequence of trials does not really matter to me at the moment. What is important is that the experiment, after the instruction follow the sequence of events below:

a)|Cue (“add the black squares” or “find the blue square”)=> 1.5 s|
b)|Four single grids ( having 2 black squares each) => 1 s each x 5= 4 s|
c)|Double grid and answer => 3750 s (max)|
d)|Fixation cross=> jittered 2000-3500 msec
At the moment
-if the two conditional excell sheets called by Condition loop have just one row the script run just fine (i.e.at the end of d) the script comes back to a) (cue).

-if the two conditional excell sheets called by Condition are a list of 20 positions the script goes from d) to b) without switching from a condition to another, but they keep going on the same condition.

What I want happening is a random alternation between the ‘add’ condition and the ‘find’ condition. If may help here a graphic representation of the two conditions.

To answer to you question the task can vary randomly trial to trial (add/find/find/add/add/find…)

![Slide12|690x388]

So it sounds like you only need a single loop (encompassing all three routines), and a single conditions file. Set the loop to “random”.

You have one row per trial, with a column specifying the “cue” condition for that trial.

Hello Micheal and thank you for your answer. Eventually I realised that this was the way to pursue. I was wondering if there were some alternative ways more “elegant” from a programming prospective (I am new to Python, so I am always worry to find the more efficient way possible). Anyway the experiment now works well and I am applying the same solution to the other experiment I have. Thank you very much for your support.

In programming terms, “elegant” usually just corresponds to “simplest”. In this case, having the smallest number of loops and conditions files would probably make this more “elegant” than alternatives.