# Unable to set specific duration for specific stimuli

**URL:** <https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [March 2, 2021, 11:17am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910 "2021-03-02T11:17:22Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 11:17am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/1 "2021-03-02T11:17:22Z")

</div>

Hello everybody,

Description of the problem: Using the builder, I am currently trying to build an online experiment in which each stimulus has a specific duration. However, when I set in the Stop parameter the name of my column of the .csv file containing the timing with the $ (e.g., $myDuration), in Pavlovia I get the following message right before the stimulus: \* **ReferenceError: asarray is not defined**

How can I solve?

Thank you

Daniele

---

<div class="post-metadata">

**Author:** ![Glen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/glen/32/3378_2.png) [@Glen](https://discourse.psychopy.org/u/Glen)\
**Post date:** [March 2, 2021, 11:34am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/2 "2021-03-02T11:34:20Z")

</div>

Hi  
In the newest version I don’t think you need the $ sign in the duration

Best wishes  
Glen

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 11:44am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/3 "2021-03-02T11:44:46Z")

</div>

Thank you, but that actually does not solve the issue.

Daniele

---

<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:** [March 2, 2021, 1:40pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/4 "2021-03-02T13:40:42Z")

</div>

What type of stimuli? I don’t think durations for sound components work.

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 1:54pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/5 "2021-03-02T13:54:13Z")

</div>

Verbal stimuli, I need each stimulus to stay on the screen for a fixed time (different across various stimuli conditions).

Thank you

Daniele

---

<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:** [March 2, 2021, 2:00pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/6 "2021-03-02T14:00:27Z")

</div>

By verbal I’m assuming audio.

> Create a sound component in an earlier routine and set the start time to after you want the routine to end. You may therefore need to end the routine using continueRoutine=False
> 
> You can then start and stop the sound in code using .play() and .stop()

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 2:02pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/7 "2021-03-02T14:02:17Z")

</div>

Sorry, to me verbal is a string of letter 🙂

---

<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:** [March 2, 2021, 2:07pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/8 "2021-03-02T14:07:42Z")

</div>

Please could you show a screenshot of your text component?

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 2:35pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/9 "2021-03-02T14:35:45Z")

</div>

I would like to show the text stimuli in the left column for a given time (right column)

![Schermata 2021-03-02 alle 15.34.10](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/7/173954b8eeaee5669053a24893c2b53dc5ce7386.png)

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [March 2, 2021, 4:12pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/10 "2021-03-02T16:12:29Z")

</div>

@Glen is right that you don’t need the `$` in `duration` as it’s already marked as literal.

This is most likely a quirk of the JavaScript translation - in Pyhon, `asarray` is used to ensure that whatever value you give as the duration, it’s easy to operate on. It may be that an equivalent function either doesn’t exist in JavaScript or has a different name - which we need to account for when creating the JavaScript code. I’ll bring this up with the JS team and make sure we’re in sync!

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 2, 2021, 4:24pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/11 "2021-03-02T16:24:24Z")

</div>

Thank you!

Daniele

---

<div class="post-metadata">

**Author:** ![Ricardo](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Ricardo](https://discourse.psychopy.org/u/Ricardo)\
**Post date:** [March 16, 2021, 7:44pm UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/12 "2021-03-16T19:44:52Z")

</div>

Hello all. Any further developments on this issue? I ran into the same problem, I am trying to set variable stimuli durations but I receive the same error message when testing in pavlovia. @Daniele_G have you found a workaround?

Thanks!

---

<div class="post-metadata">

**Author:** ![Daniele\_G](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/daniele_g/32/8270_2.png) [@Daniele\_G](https://discourse.psychopy.org/u/Daniele_G)\
**Post date:** [March 17, 2021, 8:53am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/13 "2021-03-17T08:53:23Z")

</div>

Dear Ricardo,  
Sorry, we changed our task, so no developments.

Daniele

---

<div class="post-metadata">

**Author:** ![pweis](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pweis](https://discourse.psychopy.org/u/pweis)\
**Post date:** [May 6, 2021, 9:44am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/14 "2021-05-06T09:44:47Z")

</div>

In an earlier version this year, I used the following code in the Begin Routine JS part of a custom code component to implement a jitter and save it to the log:

```auto
jitter = (0.6 + Math.random() * 0.4);
psychoJS.experiment.addData("jitter", jitter);

```

I used to put in “$jitter” in the duration part of the respective text component that needed to be jittered.

**Now, the following changed:**

in addition to defining jitter the way described above I now write the following in the start experiment JS part (as suggested by wakecarter somewhere else):

```auto
asarray=function(jitter) {
return jitter;
}

```

also, I now need to put “jitter” without the dollar sign in the duration part of the respective text component that needs to be jittered

---

<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:** [May 6, 2021, 10:53am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/15 "2021-05-06T10:53:19Z")

</div>

What version of PsychoPy are you using? I’m hoping that this isn’t needed for 2021.1.3 onwards.

---

<div class="post-metadata">

**Author:** ![pweis](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pweis](https://discourse.psychopy.org/u/pweis)\
**Post date:** [May 6, 2021, 10:58am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/16 "2021-05-06T10:58:29Z")

</div>

OK that’s great news! I am using 2021.1.2 but hesitant to upgrade so I don’t break anything else!

---

<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:** [May 6, 2021, 11:26am UTC](https://discourse.psychopy.org/t/unable-to-set-specific-duration-for-specific-stimuli/20910/17 "2021-05-06T11:26:05Z")

</div>

Unless you’re mid data collection then I’d recommend that you upgrade.
