How can I go from one routine to another in a probabilistic way?

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 1.85.2
Standard Standalone? (y/n) yes
What are you trying to achieve?:

Hi,

I am making self-paced reading task. I want to make participants read sentences (e.g. Judy met Tom last Saturday) and with a 20% chance, I want them to solve probe question (e.g. Did Judy meet Tom last Saturday?) with yes or no answer. I made two different routine, one for reading sentences, and another for this questions. Sentences and their relevant probe questions are all stored in one EXCEL file but two different routines recruit two different columns with sentences and probe questions respectively. I made everything else go well but the current design makes participant meet this probe question 100% of the trials.

image

Long story short, I want to make that ā€˜trial1ā€™ routine to go to ā€˜probe1ā€™ routine 20% of the time participants solve it. For 80% of the time, I want them to skip the ā€˜probe1ā€™ and go to ā€˜cross1ā€™ routine which shows them fixation cross.

Thank you for reading!

Hi, this will take a little code. On each trial, get a random number and use it to control which routine runs.

Insert a code component on the first routine. In its ā€œend routineā€ tab put something like this:

if random() >= 0.8:
    option = 'probe'
else:
    option = 'cross'

thisExp.addData('option', option) # save to data

Then in a code component on the probe routine, put this in the ā€œbegin routineā€ tab:

if option != 'probe':
    continueRoutine = False

Similarly on the other routine:

if option != 'cross':
    continueRoutine = False

Hi Michael,
Thank you for your reply.

I adopted this and it doesnā€™t work properly. What I found out was that most of the time, the fixation cross ā€˜crossā€™ disappears from every trial and there is probe appearing every trial. I think this random number defined at the initial trial is somehow fixed. And it is fixed higher than 0.8 everytime. Below is the ā€˜optionā€™ column of the data after I ran a few trials.

I already have code component in the ā€˜trial1ā€™ routine. Its ā€˜Begin Routineā€™ and ā€˜Each Frameā€™ tab is filled with some codes but there was nothing in the ā€˜End Routineā€™ tab before I put this code in. I donā€™t think they interacted each other. I also tried creating an additional code component with only ā€˜End Routineā€™ filled with your code so that there will be two separate code component in the ā€˜trial1ā€™ routine. But this did not change anything. I donā€™t think there is a problem with codes in other routines (ā€˜probe1ā€™ or ā€˜cross1ā€™). Why would the random number not change? And why is it fixed to probe all the time? I wonderā€¦

Just in case that it is something to do with loop, I attached this capture. It shows how I set the parameters in the loop.

image

Best,
Kyung-Hwan

Sorry, I typed that post on an iPad which was a bit laborious, and there was a typo in the code (now amended). In particular note that if random should have been if random()

1 Like

Oh, why did I not catch that?

It works beautifully!

Thank you very much.