# Screen stuck due to a code component

**URL:** https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408
**Category:** Online experiments
**Created:** [January 6, 2021, 7:30am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408 "2021-01-06T07:30:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Tingyu\_Huang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tingyu_huang/32/13258_2.png) [@Tingyu\_Huang](https://discourse.psychopy.org/u/Tingyu_Huang)
#### Post date: [January 6, 2021, 7:30am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/1 "2021-01-06T07:30:22Z")

</div>

URL of experiment: [https://pavlovia.org/run/Tingyu/condition-1/html/](https://pavlovia.org/run/Tingyu/condition-1/html/)  
Description of the problem:  
Hi all,

I have a code component which enables participants to replay sounds by clicking buttons on the screen. It runs well offline. I chose Auto \> JS code type, but screen stuck online and the error message is: core.wait is not a function.

My code is:  
if (mouse.isPressedIn(polygon\_8)) {  
sound\_8.play();  
core.wait(sound\_8.getDuration());  
sound\_8.stop();  
}

I cannot figure out which function to use online, thus help would be appreciated!  
Thanks!  
-Tingyu

---

<div class="post-metadata">

### Author: ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)
#### Post date: [January 6, 2021, 2:15pm UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/2 "2021-01-06T14:15:05Z")

</div>

Hello,

core.wait is PsychoPy function, not a PsychoJS function, see [here](https://discourse.psychopy.org/t/typeerror-core-wait-is-not-a-function/19317).

Best wishes Jens

---

<div class="post-metadata">

### Author: ![Tingyu\_Huang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tingyu_huang/32/13258_2.png) [@Tingyu\_Huang](https://discourse.psychopy.org/u/Tingyu_Huang)
#### Post date: [January 8, 2021, 5:06am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/3 "2021-01-08T05:06:13Z")

</div>

Thanks Jens! Is there any alternative function that I can use instead of core.wait?

---

<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: [January 8, 2021, 8:01am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/4 "2021-01-08T08:01:47Z")

</div>

You could put the sound into a separate feedback routine.

---

<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: [January 8, 2021, 8:18am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/5 "2021-01-08T08:18:23Z")

</div>

Alternatively, start the sound and save the value of t and then check if t \> savedT+x and savedT \> 0 then stop the sound and reset savedT to 0

x should be the known length of sound 8

---

<div class="post-metadata">

### Author: ![Tingyu\_Huang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tingyu_huang/32/13258_2.png) [@Tingyu\_Huang](https://discourse.psychopy.org/u/Tingyu_Huang)
#### Post date: [January 8, 2021, 8:37am UTC](https://discourse.psychopy.org/t/screen-stuck-due-to-a-code-component/19408/6 "2021-01-08T08:37:24Z")

</div>

Thanks Wakefield! I’ll try and hope it can resolve my problem.
