| Reference | Downloads | Github

Randomly Select Routines or Turn Code On/Off

I have finalized an experiment that includes different levels of reinforcement to various cues when a click to the target stimulus is made. I have created all of the possible routines (4 in my screenshotted sample but in reality 16) that can occur in my experiment and can easily duplicate them so that they fit my desired contingencies. Thus for 1 cue that is reinforced 100% of the time I have created 4 routines that are identical, for a different cue that is reinforced 25% of the time, I would create 1 routine where the code for reinforcement exists and 3 others that are identical but I eliminate that code. As I now have 16 routines, I have put them into a loop to be repeated 6 times, but I would like the selection of the presented routine to be random. I have been unable to accomplish this even when I select the “random” setting for my looptype.

I also understand that this is not the most kosher way of creating these types of experiments so have created a version that I think fits the model of how most people create their experiment, but I run into a similar dilemma. Here I have created only 1 routine and linked it to the excel file seen below.

The problem is I do not know how to conditionalize my Code4Response code component so that sometimes it is turned on and sometimes turned off according to the other elements in its row.

Thus my two questions are: 1) Using my messier version, is there a simple way to randomize the selection of the presented routine in a loop and/or 2) is there a way to turn on/off a code component for each trial using the same routine?

I think you’d just have it all in the same code component and have an if statement:

if Code4Response == 'Yes':


best wishes,


@oli is correct re selective code execution. I suspect you can use that approach to radically simplify your experiment. i.e. it is highly doubtful that you really need 16 different routines: that level of duplication usually indicates something going wrong. In fact, it is quite possible that you only need one routine, whose behaviour is contingent on various factors.

If you truly need quite different routines, then yes, the selection of one on a given iteration of a loop can be achieved. But first you should isolate exactly what is different between each trial and see if it can be achieved by modifying a single routine. This will also greatly simplify your data analysis, as your variables will wind up in the same column in the data output file.