| Reference | Downloads | Github

Run code before each component

Hello all! I was wondering if there was a way to run code before each component in a routine. Right now, my code sends triggers to my data file at the beginning of each routine. I did this by including the trigger code as a separate routine at the beginning of my experiment and then in each routine with stimuli, adding a code component in the “Begin Routine” section that ran the trigger code. However, ideally I want it to send triggers at the beginning of each component, i.e. beginning of instructions, beginning of fixation screen, beginning of visual stimuli, etc. I figured I could accomplish this by making each of my components a separate routine but is there a simpler way?

Making each of them a routine seems like better practise anyway - it gives you more control over exactly this sort of thing. You could make a code component to add a row of data when the same conditions controlling each component are met, but honestly I think splitting them into routines is the way to go.

Thank you! Just as a last point of investigation—do you know if there’s a way to get the code to run at specified time points during the routine? I.e run at 10 seconds, 30 seconds, and 500 seconds?


In Each Frame put

if t > 10 and code10run == False:
     code10run = True
elif t > 50 and code50run == False:
1 Like