How to change the Stimulus Onset Asynchrony(SOA) according to the participant's reaction in the last trail

Hi, I meet a new pronlem and hope you can help me .I am designing a Stop Signal Task, which prensent two stimulus.One is for going to press the key,after that ,the other one show meaning to withdraw.I want to the SOA between the two stimulus change according to the participant’s reaction .The original soa = 200ms,if the participant behave right ,then soa will add 17ms radomly in next trail.If not, soa will reduce 17 ms radomly.
In builder,I write codes at the begining of the rotutine and the end of the routine respectly.And the second stimulus start time is $soa.Code like this:

(at the begining of the routine)

soa = 2.5

(at the end of routine)

import random
i = random.randint(1,3)
if response.corr == 0:
soa += i0.017
else:
soa -= i
0.017

the whole program can run,but when I examine the result in excel find it may not be exacty what I want.Am I wrong ,if so ,how to revise?

Hi @Melody, what output are you receiving, and how is it incorrect?

@dvbridges Thanks for your attention…My program can ran successfuly,but the soa in every trails seamed to be same.
How can I improve my code?


Thanks @Melody, can you please show me the code in the “Begin Routine” tab as well?

Yes@ dvbridges,here it is;

Thanks. So, the SOA is the same on every trial because it is reset to 2.5 on each routine, and only incremented at the end of the trial. You could instead move soa = 2.5 to the “Begin Experiment” tab.

You are right!Thanks again , I really appreciate your help!@ dvbridges