Display a blank screen randomly in a routine

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2024.1.4
I am trying to display a “blank” screen right after a cue and right before a text stimulus. In one trial, there willbe a cue, maybe a blank screen, and a text stimulus. I wanted to loop this for 20 times (i.e., 20 trials). The problem is within the loop of 20 trials, I want the blank screen to be displayed randomly trial-wise. In other words, some trials will have a blank screen before the stimulus, some will not have the blank screen at all. I am not sure what to add for the code component… I looked at other threds, but it seems like randomly dispayed issues often focuses on display either this or another stimulus.

I appreciate all the help and insights from anyone.

Thank you.

The easiest way to “present” a blank screen is to have an empty text component.

Here is one way to achieve what I think you want.

  1. Create a cue routine with a fixation cross that starts at 0 and ends at whatever, e.g. 0.5s.

  2. Add a blank text component to the cur routine which starts at 0 and ends at a variable called blankScreen (still in seconds).

  3. Add a code component to the cue routine. Move it to the top.

Begin Experiment

blankScreens = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1]
shuffle(blankScreens)

Begin Routine

blankScreen = blankScreens.pop() * 1.5 # replace with total duration of cue plus blank
#blankScreens[trials.thisN] * 1.5 will also work
  1. Add a trial routine with the text stimulus and response starting at 0s
1 Like

Hi @wakecarter,
Thank you very much for showing me how to do this! I tried it out and it worked perfectly. I truly appreciate your help!!!

One more question though, with the code

blankScreens = [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1]

does that mean the blank screen will appear 10 times out of 20 trials? Also if I want to test with 10 trials, I should put change to five 0s and five 1s instead? Also,

blankScreens = [0,0,0,0,0,1,1,1,1,1]

Thank you very much once again.

Yes, that’s correct.

Just wanted to chime in here.

Depending on the nature of your experiment it might be more appropriate to include a blank screen as an experimental manipulation. Meaning that in your experimental design it would be another independent variable. As it is right now, it is not technically random as this implementation just has an equal number of blanks and non-blanks. In a more “random” presentation of blanks/no-blanks there is more likely to be an uneven number between the two. With how it is now, certain variable categories may have blank screens more often than others.
Issac

Thank you for your inputs Isac @stanley1O1 & Wakefield @wakecarter

I am aware that the solution Wakefield kindly showed me is not technically random since there is an equal amount of blanks and non-blanks; parts of the experiment will need an equal amount of blank screens vs. no blank screens throughout all trials. This solution helped me with displaying the blank screen randomly timewise.

Though, I am wondering if I can set the screen values of 0s and 1s in an Excel file if I increase the trial conditions up to around 100 or 200 trials…? I don’t think it’s efficient to continuously add fifty 0s and fifty 1s in the code component.

What I do for larger numbers of trials is shuffle a shorter list every x trials.

For example

if trials.thisN % 20 == 0:
     shuffle(blankScreens)
blankScreen = blankScreens[trials.thisN % 20] * 1.5

If you are using Python 10 you might need to change this for the auto translate to work

if trials.thisN % 20 == 0:
     shuffle(blankScreens)
thisTrial = trials.thisN % 20
blankScreen = blankScreens[thisTrial] * 1.5
1 Like