psychopy.org | Reference | Downloads | Github

Running a loop for different lengths of time relative to another routine

Hello,

In this experiment, participants will hear an audio file then provide a saliva sample and respond to questions at multiple time points.

These time points vary with reference to the end of the audio file: 0min post, 5 min post, 15 min post, 30 min post.

One approach to cue participants was to create wait time windows that would start after the Qs and would vary based on what I determined within an excel file. While this works, this could lead to variability in when the prompts appear and how long the experiment runs for overall, since people could take different amounts of time to provide the samples/respond to my questions.

Ideally, I would like the sample/Q routines to appear at the exact time intervals after the initial stimulus, not at relative times to other routines.


Would I need to go into the coder to do this? Suggestions for appropriate code would be greatly appreciated!

No, Builder provides for “code components”, available from the “custom” component panel. These allow you to enter the custom code you need, without having to directly edit the generated .py file.

Please precisely and fully describe what you want to achieve (think the level of detail you would need in a methods section), while referring to the names of the routines as shown in your screenshot above. e.g. at the moment, we don’t know from the screen shot above when the various events (such as the audio stimulus) will occur and what intervals need to be between them, and if that is even the full relevant section of the flow panel.

But as a starter hint, let’s say that you want to start the time from the beginning of the routine on which an audio stimulus is presented, then you could put something like this in the “begin routine” tab of a code component on that routine (I’m assuming you have a variable called, say, prompt_delay in your conditions file, that contains, 0, 5, 15, etc):

# start counting down from the specified duration in seconds:
prompt_countdown = core.CountDownTimer(prompt_delay * 60)

Then you would have a delay routine that would, say, just contain a text stimulus with an indefinite duration. Then in a code component on that routine, you would put something like this in its “each frame” tab (so the code will run once per screen refresh during that routine, typically at 60 Hz):

if prompt_countdown.getTime < 0:
    continueRoutine = False

i.e. this delay routine would run for whatever amount of time is left over since the start of the stimulus and the asking of questions and so on. If that time has already elapsed (because the delay is 0, or the subject took a long time), then the routine will end straight away.