# How to set different duration time as the same in number

**URL:** <https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937>\
**Category:** Builder\
**Created:** [August 17, 2017, 2:18am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937 "2017-08-17T02:18:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 17, 2017, 2:18am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/1 "2017-08-17T02:18:04Z")

</div>

Hi, everyone. Forgive me will ask a silly question. It’s my first time using psychopy, everything goes well, but I want make my experiment more easily to analyze. Then I met a question difficult for me to solve, I really need your help.  
I designed my experiment with builder. During my experiment, I will show participants a cross for different duration time as 2s, 4s, 6s and 8s, so I write two lines code with code component as:

```auto
duratimelist = [2, 4, 6, 8]
duratime = duratimelist[randint(0,4)]

```

and this code goes well. My problem is I don’t want to show the cross in really random duration time, actually I want to show the cross in 2s, 4s, 6s and 8s 12 times each. I think I need a code to set this condition but I don’t know exactly what kind of code. Pleas help me. Really thank you very much.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 17, 2017, 11:10pm UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/2 "2017-08-17T23:10:31Z")

</div>

This is very common. What you want to do is create all the combinations you want, randomly shuffle that list, and then extract items from the list as required.

e.g.

```auto
# probably in the "Begin experiment" tab of a code component,
# create a list with 48 elements:
duration_list = [2, 4, 6, 8] * 12 

#randomise its order: 
shuffle(duration_list)

```

Then at later points in the experiment, you can extract the next value in the list. e.g. perhaps in the “Begin routine” tab, get a value for the current trial:

```
trial_duration = duration_list.pop()

```

NB you probably want to save that value in the data so at the analysis stage you know what happened, so also add a line like this:

```
# ensure it gets saved in the data for this trial:
thisExp.addData('duration', trial_duration)
```

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 18, 2017, 5:38am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/3 "2017-08-18T05:38:15Z")

</div>

Hi, Michael. Thank you very much.  
It worked! Really helped me a lot. This “problem” confused me for a while.  
I think I should learn some thing about python or more about psychopy.  
Really thank you very much.

Hu

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 20, 2017, 8:19am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/4 "2017-08-20T08:19:22Z")

</div>

Hi, Michael.  
Sorry to bother you again.  
As I replied earlier, the code you taught me goes really well, and the trial\_duration form was appeared in the data file. But, only the title appeared, the duration time didn’t appeared in the csv file or the log file. Would you help me again? I am not sure wether I should ask this question in a new topic. I know that directly ask you a question again is not good, but forgive and please help me.  
Thank you very much.

Hu

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 20, 2017, 10:41pm UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/5 "2017-08-20T22:41:44Z")

</div>

> [@qtfy\_hu](#):
>
> only the title appeared, the duration time didn’t appeared in the csv file or the log file

That is strange. Try adding a line like this:

```auto
# ensure it gets saved in the data for this trial:
thisExp.addData('duration', trial_duration)
print(trial_duration) # just temporarily, for debugging

```

and check the output window after the experiment has run what values are being printed.

Also NB the code component needs to be _ **above** _ any component that uses the `$trial_duration` variable, so that it gets the correct value of the variable as updated for this trial, and not the previous one.

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 21, 2017, 3:15am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/6 "2017-08-21T03:15:47Z")

</div>

Hi, Michael.  
Thank you for your reply and your kindness.  
I did put the code component above the component that would run the trial\_duration variable.  
I tried to print the duration time out, as the picture below shows, it worked well I think.

 ![31](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/4/244becbfd7a7de53833082b5866d719f311c2d0f.png)

But it still didn’t appear in the csv file and the log file.

 ![52](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/6/8609844a5fedf3d6ef305b19b466e6208e06b6a2.png)

And there is another not good news, the key responses also gone from the csv file, but the good news is key responses all recorded in the log file.

I still use the previous version, wether updating to the latest one could solve the problem?

Your replies really helped me, and made me less nervous.  
Thank you so so much.

Hu

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 21, 2017, 3:29am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/7 "2017-08-21T03:29:14Z")

</div>

Can you send a screenshot of the “data” tab of your “experiment settings” dialog?

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 21, 2017, 3:38am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/8 "2017-08-21T03:38:03Z")

</div>

Hi, Michael.

This is the screenshot of the data tab of experiment settings.

 ![08](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/8/7809e5ab5c9d96154b7d4697bad5b8f1e7d44f61.jpeg)

If I made some basic mistakes, please forgive me taking so much of your time.

Hu

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 21, 2017, 3:50am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/9 "2017-08-21T03:50:56Z")

</div>

Please uncheck the “Save csv file (summaries)” check mark. This format isn’t very useful to anyone these days (it tries to do some summaries of the data (taking means and so on), but what you want are the raw, trial-by-trial lines). I’m hoping that will show you more clearly which .csv files to examine.

Also uncheck the Excel option. That can cause performance problems.

_We really should hide those two options safely away from people._

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 21, 2017, 4:06am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/10 "2017-08-21T04:06:35Z")

</div>

Michael,  
I unchecked the two marks you told me, but it still not work…

Hu

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 21, 2017, 5:31am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/11 "2017-08-21T05:31:50Z")

</div>

It’s not the lack of the duration field that is puzzling so much as the lack of almost all other information as well. We probably need to see your Builder.psyexp file uploaded here.

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 21, 2017, 6:07am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/12 "2017-08-21T06:07:24Z")

</div>

Hi, Michael.  
Really thanks to help me a lot.  
I uploaded my builder file named “test”.  
Hope that will help you to find the problem I met.  
Really thanks for your kindness.

Hu

[test.psyexp](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/2X/8/8d23f164be0a8920fdfca646803b4b28dae0ea6e.psyexp) (20.3 KB)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 21, 2017, 6:30am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/13 "2017-08-21T06:30:46Z")

</div>

In your loop dialog, please check “is trials”. This tells Builder that this loop is running trials and data should be saved.

The option is there because sometimes we just want to repeat things within a trial and not have any data associated with it. But almost always, you want this enabled.

---

<div class="post-metadata">

**Author:** ![qtfy\_hu](https://avatars.discourse-cdn.com/v4/letter/q/8491ac/32.png) [@qtfy\_hu](https://discourse.psychopy.org/u/qtfy_hu)\
**Post date:** [August 21, 2017, 6:45am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/14 "2017-08-21T06:45:46Z")

</div>

Michael,

What a stupid mistake I made.  
Sorry bother you with such a stupid problem. I didn’t note it. Really sorry!  
But thank you for solving this problem for me.  
Please don’t ignoring my future questions though they probably be other stupid questions.  
Really thank you for your kindness.  
Have a good day and good luck.

Hu

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [August 21, 2017, 7:58am UTC](https://discourse.psychopy.org/t/how-to-set-different-duration-time-as-the-same-in-number/2937/15 "2017-08-21T07:58:24Z")

</div>

Don’t worry, it’s a subtle issue. Good luck with your study.
