# Create a fixed length Stroop task

**URL:** <https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496>\
**Category:** Builder\
**Created:** [December 19, 2022, 3:40pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496 "2022-12-19T15:40:21Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 19, 2022, 3:40pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/1 "2022-12-19T15:40:21Z")

</div>

Hi ,

I tried to create a Stroop task (which I think I managed) however I want it to be fixed at a total 30 min and not dependent on the performance and rapidity of the participant’s answers… How can I make that the whole task has a duration of 30 min?

Thanks for your help.

Jil

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 19, 2022, 8:14pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/2 "2022-12-19T20:14:48Z")

</div>

You need a custom clock and to break the loop when the elapsed time is over 1800.

```auto
myClock = core.Clock()

```

```auto
if myClock.getTime() > 1800:
     trials.finished = True

```

Make sure your loop repeats often enough that no-one will run out of trials in 30 minutes.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 20, 2022, 3:27am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/3 "2022-12-20T03:27:43Z")

</div>

Hi,

Thanks for your reply!  
So this means I have to just insert these few lines into my code? Or how should I do that?  
and where exactly in my code do I have to write this down?  
Sorry for all those questions but I am really bad at coding so I am a bit lost…

Best

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 21, 2022, 3:52pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/4 "2022-12-21T15:52:28Z")

</div>

Try adding a code component. Create the clock in Begin Experiment. You can reset it using myClock.reset() in End Routine before the loop starts. Then put the check in End Routine of the last routine within the loop (called trials by default – change trials in the code if your loop is called something else). This should end the loop at the end of a trail when the time has been exceeded.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 7:40am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/5 "2022-12-22T07:40:33Z")

</div>

Hi Thanks a lot again for your help

I tried this out but it doesn’t work… when I try to start the experiment it shows the instructions and then it closes immediately… do you know what the problem could be?  
I am really lost… ☹

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 7:46am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/6 "2022-12-22T07:46:45Z")

</div>

Is there an error message in the runner?

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 8:24am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/7 "2022-12-22T08:24:31Z")

</div>

This is what I get

## Running: C:\Users\JilBo\OneDrive - CONDOR COURTIERS & CONSEILLERS SARL\PhD\_Mental\_Fatigue\Stroop Task\StroopT\_lastrun.py

731.6467 EXP Imported C:/Users/JilBo/OneDrive - CONDOR COURTIERS & CONSEILLERS SARL/PhD\_Mental\_Fatigue/Stroop Task/conditions.xlsx as conditions, 10 conditions, 4 params  
731.6500 INFO Loaded monitor calibration from [‘2022\_05\_15 19:11’]  
731.6703 EXP Imported C:/Users/JilBo/OneDrive - CONDOR COURTIERS & CONSEILLERS SARL/PhD\_Mental\_Fatigue/Stroop Task/conditions.xlsx as conditions, 10 conditions, 4 params  
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)  
Traceback (most recent call last):  
Hello from the pygame community. [Contribute - pygame wiki](https://www.pygame.org/contribute.html)  
2.5911 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’, ‘PTB’, ‘pyo’, ‘pygame’] (in that order).  
11.6025 WARNING User requested fullscreen with size [1024 768], but screen is actually [1920, 1080]. Using actual size  
0.9760 WARNING Monitor specification not found. Creating a temporary one…  
File “C:\Users\JilBo\OneDrive - CONDOR COURTIERS & CONSEILLERS SARL\PhD\_Mental\_Fatigue\Stroop Task\StroopT\_lastrun.py”, line 222, in   
trials = data.TrialHandler(nReps=None, method=‘random’,  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\trial.py”, line 147, in **init**  
self.nReps = int(nReps)  
TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’  
################ Experiment ended with exit code 1 [pid:27764] #################  
749.6061 EXP Imported C:/Users/JilBo/OneDrive - CONDOR COURTIERS & CONSEILLERS SARL/PhD\_Mental\_Fatigue/Stroop Task/conditions.xlsx as conditions, 10 conditions, 4 params  
749.6119 INFO Loaded monitor calibration from [‘2022\_05\_15 19:11’]

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 8:45am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/8 "2022-12-22T08:45:03Z")

</div>

> [@Jil](#):
>
> self.nReps = int(nReps)

What value do you have for nReps for the trials loop? I’d recommend a large number like 9999.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 9:59am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/9 "2022-12-22T09:59:17Z")

</div>

I tried with not putting any number in it at first then it didn’t work and then I put 10000000 and then it crashed… could it be that the number is too big?  
You said to use a high number but how can I make sure the number is big enough?

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 10:08am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/10 "2022-12-22T10:08:43Z")

</div>

> [@Jil](#):
>
> TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’

The number needs to be big enough so it would take longer than 30 minutes to complete all the trials.

What is the minimum duration of each trial (in seconds)?  
How many trials are displayed if nReps = 1?

Multiply these two numbers together.

Divide 1800 by this number and round up.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 10:10am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/11 "2022-12-22T10:10:38Z")

</div>

I have that the duration of each trial is 60sec  
how can I adjust the number of trials displayed for nReps?

I have 10 conditions with 4 parameters (that’s what my trial window tells me)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 10:22am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/12 "2022-12-22T10:22:00Z")

</div>

60 seconds seems a long time for one trial – in a Stroop task you normally have a fixation, then a word, then a response, then feedback or a gap.

The number of trials displayed for each repeat is the number of lines in the associated spreadsheet (i.e. 10).

Based on the numbers you’d given then each rep will take 10 minutes (60 x 10) so you’d only need nReps to be 3 to reach half an hour. However, I suspect that 60 seconds is not what you meant to type.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 10:25am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/13 "2022-12-22T10:25:10Z")

</div>

Is the time for one trial not this

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/1/a1fe6d7a41f0c94c2d38f06ce02bab462d6f74aa.png)

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 10:26am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/14 "2022-12-22T10:26:23Z")

</div>

so the number of trials is then in my case 10?  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/d/8d0858644d4e1620a24988220d1dddda43cba37d.png)

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 10:28am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/15 "2022-12-22T10:28:22Z")

</div>

or where do I have to set the duration of each trial? I was not planning on giving any feedback to the participants but I wanted them to complete the task for 30min in a row (I am trying to induce mental fatigue)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 11:11am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/16 "2022-12-22T11:11:54Z")

</div>

The 60 duration is the maximum duration of each trial (technically 60.5 seconds since the duration doesn’t start until 0.5). I suspect you have a keyboard response which ends the trial when a key is pressed, so the minimum trial duration is probably about 0.6 seconds. That would give a minimum of 6 seconds per repetition, so 10 reps in a minute, 300 reps in 30 minutes. Try nReps = 300.

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 11:42am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/17 "2022-12-22T11:42:45Z")

</div>

alright thanks a lot!! I will try and let you know 🙂 THANK YOU SO SO MUCH

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 22, 2022, 2:57pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/18 "2022-12-22T14:57:34Z")

</div>

Hey

Just wanted to let you know that it seems to work now 🙂 thanks a lot for your help!!

One more thing… is it possible to connect a Cedrus response pad for the input/ response? this would maybe make it a bit easier for the participants to answer instead of using the keyboard of my laptop

thanks

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [December 22, 2022, 3:47pm UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/19 "2022-12-22T15:47:48Z")

</div>

In principle, yes Cedrus response pads should be compatible. I would check exactly what model you have an search the forum for information.

See also

[https://www.psychopy.org/api/hardware/cedrus.html](https://www.psychopy.org/api/hardware/cedrus.html)

---

<div class="post-metadata">

**Author:** ![Jil](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jil](https://discourse.psychopy.org/u/Jil)\
**Post date:** [December 23, 2022, 3:21am UTC](https://discourse.psychopy.org/t/create-a-fixed-length-stroop-task/32496/20 "2022-12-23T03:21:57Z")

</div>

thank you
