# Loop medias do not change

**URL:** <https://discourse.psychopy.org/t/loop-medias-do-not-change/47340>\
**Category:** Online experiments\
**Tags:** sound\
**Created:** [June 20, 2026, 4:30pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340 "2026-06-20T16:30:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 20, 2026, 4:30pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/1 "2026-06-20T16:30:45Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**Mac Tahoe**  
**PsychoPy 2026.1.3**  
**Standard Standalone Installation? (y)**  
**URL of experiment: localhost**  
**Do you want it to also run locally? (y)**  
I have a loop including three routines. In the first three variables are assigned values like ‘sound1=voice1.mp3’, the second has a sound component named sound1\_go playing $sound1, and the third plays $sound\_2 and $video\_1. The values change in every loop. The program runs smooth locally. when I deploy it online, with all media files preloaded, the routines play the same three media in every loop. They do not change. the logs shows that the loop advances but the variables like ‘sound1\_go.sound’ keeps ‘undefined’, while ‘sound1’ changes as assigned from the first loop. I return to local program and find, even the program run correct but the ‘sound1\_go.sound’ keeps ‘A’. I use stop() and setSound() in the begin routine tab, these problems persist. Please help me make it run correct.

---

<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:** [June 20, 2026, 7:14pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/2 "2026-06-20T19:14:53Z")

</div>

Are you using code components when you could just be using sound components?

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 21, 2026, 1:18am UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/3 "2026-06-21T01:18:17Z")

</div>

Thank for your reply! I have complicated rules to follow, so these medias cannot be passed through loop itself.

---

<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:** [June 21, 2026, 7:08am UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/4 "2026-06-21T07:08:03Z")

</div>

You can still set the sound file via a sound component, without the value coming from a spreadsheet. However, the $ is only relevant if you do this. Please could you show exactly how you are setting the sound?

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 21, 2026, 11:36am UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/6 "2026-06-21T11:36:47Z")

</div>

1st routine

clpv\_this=clpv[pos]  
scene\_this=scenes[pos]

has\_visual=True  
has\_voice=True

if clpv\_this==“0pni”:  
voice\_context=“media/hongsaystoming.mp3”  
mov\_target=“media/”+scene\_this+“I.mp4”  
voice\_target=“media/”+scene\_this+“PN.mp3”  
elif clpv\_this==“0pnp”:  
voice\_context=“media/hongsaystoming.mp3”  
mov\_target=“media/”+scene\_this+“P.mp4”  
voice\_target=“media/”+scene\_this+“PN.mp3”  
elif clpv\_this==“nncc”:#C=CPV  
voice\_context=“media/”+scene\_this+“N.mp3”  
mov\_target=“media/”+scene\_this+“C.mp4”  
voice\_target=“media/”+scene\_this+“NC.mp3”  
elif clpv\_this==“nnnc”:#C=xNx  
voice\_context=“media/”+scene\_this+“N.mp3”  
mov\_target=“media/”+scene\_this+“C.mp4”  
voice\_target=“media/”+scene\_this+“NN.mp3”  
elif clpv\_this==“npii”:#I=CPV  
voice\_context=“media/”+scene\_this+“N.mp3”  
mov\_target=“media/”+scene\_this+“I.mp4”  
voice\_target=“media/”+scene\_this+“PI.mp3”

…about 3000 lines, the media files in every loops are subject to change by the participants’ answers, the value are stored in clpv[] and scene[], in some occasions has\_visual or has\_sound is set as ‘False’

2nd routine

a sound component only, plays voice\_context

start 0.1 /end empty /sound $voice\_context = every repeat (gray)

3rd routine

a sound and a movie component play at the same time

start $has\_voice /end empty /sound $voice\_target = every repeat (gray)

start $has\_visual /end empty /sound $movie\_target = every repeat ( NOT gray)

following with a series of other routines I think don’t matter

I use object.sound and setSound() only for debug

---

<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:** [June 21, 2026, 1:37pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/7 "2026-06-21T13:37:42Z")

</div>

That looks fine. Try some print statements to check the sound variables just before you use them

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/4):
>
> Use Print statements When debugging, print statements can be very helpful to track down errors or unexpected behaviour. I tend to use them in one of two ways: print('trial setup started') Sometimes I won’t know where the error is, especially if there is a problem during the initial setup of the components or Begin experiment code. The components of each routine are set up in turn from top to bottom. Therefore, if you have a flow with routines called start, trial and finish and put print('tri…

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 21, 2026, 2:17pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/8 "2026-06-21T14:17:42Z")

</div>

I added codes to 2nd routine in begin routine tab, and used print(voice\_context) and so on, found these variables were correctly passed from cplv[] and scenes[]; at the same place I used print(2nd\_routine\_sound.sound) got all ‘A’ locally but the sound was played as designed in every loop; while online, in browser console I got 2nd\_routine\_sound.sound as ‘undefined’ and in every loop the program kept playing the first sound, i.e., the first set of sounds and video were played throughout the loops. the loop counts check was ok.

When debugging, I also tried to add 2nd\_routine\_sound.stop() at the begin routine tab and used setSound(), nothing changed, either locally or online.

I am extremely confused with the internal mechanism of the sound component.

Thanks for your reply!

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 21, 2026, 2:27pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/9 "2026-06-21T14:27:11Z")

</div>

![ud](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/a/9a125c37a7e33f0ca496e764c231aca082211ca7.jpeg)

 ![as](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/6/f6f0c2aa0abeaba70caaa31b9955574cc8d7246a.jpeg)

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 21, 2026, 2:39pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/10 "2026-06-21T14:39:15Z")

</div>

I also added print(2nd\_routine\_sound.sound) in each frame and end routine, all ‘A’. it seems the soundPTB object behind sound component does not change throughout the routine. I tried to find some method like refresh() but failed.

---

<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:** [June 22, 2026, 9:33pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/11 "2026-06-22T21:33:04Z")

</div>

> [@Chester](#):
>
> at the same place I used print(2nd\_routine\_sound.sound)

If you have the code component above the sound component and check the value of the variable in Begin Routine then the sound component won’t yet have been set to the value, which is probably why you’re seeing it as the default. How about checking it in Each Frame code, e.g.

```auto
if frameN == 5:
     print("2nd_routine_sound.sound",2nd_routine_sound.sound)

```

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/9):
>
> Code components go at the top When you add components to a routine they will, by default, appear in the order you create them. This is also, however, the order in which they get processed. I recommend that when you create a code component you move it to the top of the routine unless you have a specific reason why it should be lower down. The main reason for this is that it means the code in the Begin Routine tab is processed before any “set every repeat” parameters are set in other components. …

---

<div class="post-metadata">

**Author:** ![Chester](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chester](https://discourse.psychopy.org/u/Chester)\
**Post date:** [June 23, 2026, 12:47pm UTC](https://discourse.psychopy.org/t/loop-medias-do-not-change/47340/12 "2026-06-23T12:47:51Z")

</div>

yes I DID add in begin routine, each frame, and end routine, all ‘A’.

For debug, I tried in begin routine:

2nd\_routine\_sound.sound=voice\_context

2nd\_routine\_sound.preload=True

Locally the values are correct, as they were designed; but

online they shows the first value for every loop, NOT ‘undefined’, but medias still play the first set.

A little forward, though.
