How to set time with button component

Hello, I am designing a dual-task with using n-back as a secondary task. In this task, participants will simultaneously see a cue-word while doing the n-back task. After the presentation of cue-word, reaction time will be recorded after the determination made by pressing the “space” button, then, after 20 seconds, participants will see a scale. I want to set this time (20s) after pressing the space button, that is, when participant press the “space” button, they should see the scale right after 20 seconds. I couldn’t do this by using builder, i guess it’ll be easier with code but unfortunately i am not capable of that. Are there any codes to set the time by using the button component?

Thank you

Hello,

let space finish your cue-word routine, add a routine containing your scale, set the start time to 20 seconds.

Best wishes Jens

Hello

do you mind sharing with us what you have tried so far? Experiment flow, routines and loops?

Best wishes Jens

I defined “n” button for n-back answers. when the cue word is presented, participant should determine what to think about cue word while doing n-back simultaneously, then once determination occurs, they should press “space” button (i didn’t define it in this file). and then, after 20 seconds after pressing “space”, the scale will prompted. (participants doing n-back task simultaneously in defined 20 seconds, that is, they will think about their determination in this 20 seconds while doing n-back)

experiment.zip (8.3 KB)

Hello bbbb

just to make sure that I understand what you intend. You have a N-Back running, while the cue-word task is running at the same time. Your participants have to do the N-Back task and the cue-word task and in addition answer on a rating scale. It this correct?

How is the timing of these tasks relative to each other? In your attached file, you have 19 N-Back trials, one cue-word trial and another 19 N-Back trials.

After how many N-Back trials should the cue word occur? Will it always be 19 or it is variable, it is time-dependent?

Do you only have one cue word or multiple cue-words?

I understood correctly that 20 seconds after reacting to the cue-word a rating scale should appear to which the participants have to react. What happens with N-Back in this case, does it continue? From your example, I conclude that 20 seconds have been reached by trial 7 of the second block of N-Back trials. What happens with the remaining 12 trials?

Best wishes Jens

After 30 trials of n-back, cue word will be shown. I will rearrange the trials, the file i sent you is just arbitrary. also i will have another cue-words but i didn’t add this file.

You understand correctly. participants will see a cue-word while doing n-back simultaneously. when the participants react to cue-word (by pressing “space”, reaction time will be recorded) timer will start to prompt scale after 20 seconds. It doesn’t matter how many n-back trials couldn’t reach by participants after the 20 seconds have been reached (also participants can see 7, 8, 9 trials within 20 seconds, it doesn’t matter). in your example, remaining 12 trials don’t matter.

I guess there should be some codes to set the time. When the time is reached, n-back routine will be ended (doesn’t matter how many trials couldn’t reach by participants) and the scale will be shown right after 20 seconds.

hello bbbb

ok, add a code component to your trial-routine. Add

cueShown = 0
loopTimer = core.Clock()

in the Begin Experiment tab, add

if cueShown == 1 and trials_2.thisN == 0:
    loopTimer = core.Clock()

to the Begin Routine tab to start a timer a loop-start. Add

if loopTimer.getTime() > 20.0 and cueShown == 1:
    continueRoutine = False
    trials_2.finished = True

to the Each Frame tab.

Add a cue-component to the cueword-routine, add

cueShown = 1

in the End Routine tab.

That did the work, at least for me. I use the routine and loop-names from your example. Notice that you need some manual translation to get this running online. The best source for this is the crib-sheet PsychoPy Python to Javascript crib sheet 2021 - Google Docs
by @wakecarter.

Best wishes Jens

It works well but I implied it differently. 20s time interval supposed to be activate by pressing “space” button after the cue word is presented. In your example, scale is presented after the 20 seconds of cue-word, however, 20 s time interval should be activated by pressing “space” button. Because to some participants it’ll take longer to have a determination about cue word, the determination will be made by pressing “space” and then 20 seconds time interval will be activated. So your code works well but I have to add keyboard component to activate this interval.

By the way, thanks for your effort, very glad!

Hello bbbb

you are right. In my example, the timer was activated when the second block of NBack-task started. In the example you provided there was only one second to react to the cue-word. :wink: So, I did not know where to put the 20 seconds to react or how you wanted to implement this interval.

Best wishes Jens
P.S. do you mind to mark it as solution?