Randomise no. of standard trials before oddball

OS : Mac Mojave 10.14.6
PsychoPy version (e.g. 1.84.x): psychopy 3 v2021.2.3

What are you trying to achieve?:
I am trying to randomise the number of standard trials (which are polygon components in my experiment, not image/movie files) before an oddball appears (also a polygon component). I would like an oddball to appear after randomly either 7, 8, 9, 10, 11 or 12 standard trials.

As my experiment is on time perception, expectation violation and subjective perceptual clarity here is some other info that may be important. After the presentation of each standard or oddball Ps have to reproduce the time (TimeRepro) that they thought the stimuli was on screen for. And then rate how clear their experience of that stimuli was on a scale (PAS). See screenshot of experiment flow.

What did you try to make it work?:
I thought that I could create a conditions excel with the variable randomise_noncritical with the numbers 7-12. I added this csv to the conditions field in the trialsExpLoop and put randomise_noncritical in the nReps field. The logic behind this is that I thought it would repeat the standard trials randomly 7-12 times before moving onto the critical trial. Screenshots
attached. HOWEVER i know that psychopy does not know that this randomise_noncritical is for the polygon component specifically, rather than the other components in the loop. Which is where I am stuck…

What specifically went wrong when you tried that?:
ANYWAY…When I run it I get an error say that randomise_noncritical is not defined.

File “/Users/hannahtyler/Documents/Cognitive Psychology Lab/Time perception and expectation violation/Expectation violation and time perception_lastrun.py”, line 1061, in
trialsExpLoop = data.TrialHandler(nReps=randomise_noncritical, method=‘random’,
NameError: name ‘randomise_noncritical’ is not defined

Experiment ended.

I know that there will be an easier solution using code, or if you would like to see the code then I will add to the thread. New to coding but feel more comfortable using the code component in the builder, rather than tackling the code viewer. Thanks in advance!




You can’t use the variable randomise_noncritical in the definition of trialsExpLoop. This loop has that variable defined in its own conditions file. i.e. that variable isn’t available until after the loop itself is created, so it can’t be used in its own definition.

What you should do is delete the reference to a conditions file in trialsExpLoop. Instead, put the randomise_noncritical variable into the conditions file for the outer loop (i.e. FullBlockLoop). That way, on each iteration of the outer loop, a value is selected for the nReps value of the inner loop that it contains.