| Reference | Downloads | Github

Varying dot numbers using random dot kinematogram

I am trying to create a numerosity discrimination task where I present different numbers of dots at varying time intervals. I have 16 conditions with 5 parameters (attached) but I cannot find a way to randomize the conditions using builder. Any suggestions?
dots.xlsx (8.4 KB)

Hi @kaplanri,

Bottom left corner of the builder window (below insert routine) there is “insert loop”. There you can specify your conditions file, if you want your conditions to be randomised or not e.t.c.

Thank you Yiannis. I tried using the “insert loop” function but since, there I cannot make the number of dots change between trials (in dots Properties) I do not know how to randomize for my conditions.


would you mind sharing your .psyexp or provide screenshots of the dots component?

Here it is.

dotsTest2.psyexp (5.84 KB)

I am baffled as well. It’s the first time I am using this component. It appears that the number of dots field refers to how many dots there should be within a series (or one) of frames within a trial, not between trials. Indeed you cannot pass a variable in this field, only positive integers.

Perhaps the reason for that is because this component is based on the paradigm reported in Scase et al. paper I haven’t read the paper - too lazy - but I suspect the answers to any Qs about this component can be found there.

An alternative is to use the shapes component. It is just how you are going to define the coordinates (no overlapping between shapes) and more experienced PsychoPy users perhaps can step in and help.

Sorry I cannot be of more help.

I am not very familiar with using this stimulus, perhaps @jon can advise. But if the Builder dot stimulus component doesn’t allow you to vary the number of dots across trials, you could presumably as an alternative create your stimulus via code (in a code component on the relevant routine). e.g. if you examine the Python script generated by Builder, you’ll see a section like this:

dots = visual.DotStim(
    win=win, name='dots',
    nDots=100, dotSize=2,
    speed=0.1, dir=0.0, coherence=1.0,
    fieldPos=(0.0, 0.0), fieldSize=1.0,fieldShape='circle',
    signalDots='same', noiseDots='direction',dotLife=3,
    color=[1.0,1.0,1.0], colorSpace='rgb', opacity=1,

You could add code like that to the “begin routine” tab of a code component, replacing the 100 value for nDots with your variable name, and altering other parameters as necessary.

See the API here for more information:

I have tried to replace the nDots number with my variable name (both in Builder and directly in the code) but there is always an error message that it doesn’t recognize the variable name, even though I have uploaded the conditions excel file. Thank you for the suggestion though.

That just indicates that the code is running before the variable has been defined. Where did you put the code?

I’m a bit confused with what you mean. I am using builder but this is the code generated from what I put in. Also, the error I get is NameError: name ‘dotsA’ is not defined. (6.66 KB)

I’m not going to read through all of that code. What I mean is that presumably you entered this code in a code component in Builder. In what tab of that component was the code? e.g. if it was in the “begin experiment” tab, then the loop doesn’t exist at that time, so its variables aren’t available. If it is in the “begin routine” tab, and that routine is inside the relevant loop, then the variable should be available.


I do not know if this can help in the discussion; I was not successful at entering the code snippet in the a code component in the Begin Routine tab (with nDots = 30, i,e. not variable). All I get is a blank grey window i.e. nothing appears on the screen and I get no error.

I get the same output even if, in the Builder, I create a Dots component and then I go the the coder window and I declare the variable dotsA during initialization.

But setting nDots=30 works just fine:


P.S. I can pass variables in the Color and Field Position fields just fine. But I cannot pass variables to Dot Size and of course to the Number of Dots fields in then Dots component

When creating stimuli in code, rather than via a Builder component dialog box, we become responsible for drawing it. (i.e. at the moment, the dot stimulus exists, but isn’t actually doing anything). So in the “Each frame” tab of your code component, simply put this line:


Hello, to solve this problem I used the code view and I just move these line of code:

dots = visual.DotStim(win=win, name='dots',
    nDots=target_num, dotSize=2,
    speed=0.1, dir=0.0, coherence=1.0,
    fieldPos=[-0.5, 0.0], fieldSize=1.0,fieldShape=u'circle',
    signalDots=u'same', noiseDots=u'direction',dotLife=3,
    color=[1.0,1.0,1.0], colorSpace=u'rgb', opacity=1,    depth=0.0)

After the trial definition and that’s all. You can use targe_num if the trial is already defined (the second for loop after the line in which your xlxs is defined.