Change isi (inter-stimulus-interal) but fix trial duration

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): macOS Mojave version 10.14
PsychoPy version (e.g. 1.84.x): v2020.2.4
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I want the duration of picture stimulus and the isi(inter-stimulus-interval) to be fixed as 2 seconds, but the picture will disappear as soon as the key is pressed, so it means that the duration of isi need to be modified.

**What did you try to make it work?:**I’m using a builder+code component. I make 2 routines, 1 for picture presentation, 1 for isi. the picture stimulus routine was “force end of routine” by a keyboard component, while the duration of isi is a variable named dura_c1_iti1, I calculate dura_c1_iti1 by the following code component inserted in the beginning of isi routine:

start_c1_enc1 = c1_enc_l1Clock.getTime()
start_c1_iti1 = c1_iti1Clock.getTime()
dura_c1_iti1 = 2-(start_c1_iti1 - start_c1_enc1)
thisExp.addData(‘dura_c1_iti1’, dura_c1_iti1)

the c1_enc_l1 is the routine name of picture stimulus, c1_iti1 is the routine name of isi routine, I want dura_c1_iti1(the duration of isi) to be the 2 seconds - (the start time of isi routine - the start time of picture routine)

**What specifically went wrong when you tried that?:**but I found the recorded dura_c1_iti1 is a negative value, which confused me a lotttt :sob:
Looking forward to your help, I appreciate it very much! thank you! :heartpulse:
Include pasted full error message if possible. “That didn’t work” is not enough information.

So you’re getting the time of one clock at the end of its routine and the time of another at the start of its routine - so when you take the difference, you get the duration of the first routine. But why are you subtracting the result from 2? If the duration of that routine is greater than 2s, then wouldn’t you expect to get a negative value?

Thank you very much for your reply, I solved this problem as you suggested, it works very well! Many thanks again! Have a nice day! :wink: :heartpulse: