Search code examples
pythontimepsychopy

Various duration in psychopy


I have an experimentation of n-back.

I have letter that appear for a maximum of 2.5 sec and then a fixation cross for 0.5 sec.

Right now: When the participant pressed on the keyboard, it ends the routine and go directly to the fixation cross. I have 60 letters so the experimentation would take at max 3 minutes, but it can be less if the participant pressed fast.

What I want : My experimentation should take 3 min at every time. So the fixation cross should stay for more than 0.5 sec if the participant answer fast

enter image description here

Do you have an idea how to do that ?

I was thinking about creating a variable that equals 3. And then if text is 2 sec then 3-2 = 1 so fixation would be 1 sec, but I was not able to write that in my code component

Thanks!!


Solution

  • In your 'trial' routine, I would record the routine starting time. Then in the 'fixation' routine, I would wait until 3 secs have passed since that starting time.

    So in 'trial' routine --> Code Component --> 'begin trial' tab:

    trial_start = core.monotonicClock.getTime()
    

    Then in the 'fixation' routine --> fixation cross component --> duration, enter:

    $trial_start + 3 - core.monotonicClock.getTime()  # 3 secs later