# Randomizing Two Lists of Stimuli within a Single Loop - Online

**URL:** <https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193>\
**Category:** Online experiments\
**Tags:** randomization, online, pavlovia\
**Created:** [January 13, 2024, 1:16am UTC](https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193 "2024-01-13T01:16:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_B](https://avatars.discourse-cdn.com/v4/letter/h/ba8739/32.png) [@H\_B](https://discourse.psychopy.org/u/H_B)\
**Post date:** [January 13, 2024, 1:16am UTC](https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193/1 "2024-01-13T01:16:46Z")

</div>

I am new to PsychoPy, and am trying to replicate the example from this tutorial on randomizing two lists of stimuli within a single loop: [https://www.youtube.com/watch?v=toQ2enxAv1E](https://www.youtube.com/watch?v=toQ2enxAv1E)

I have been able to replicate this and run it locally, but when I push the experiment to Pavlovia I keep getting the following error:

 ![Screenshot 2024-01-12 at 8.06.49 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/0/6/06580a1e04dc96dcb6ec5c45e437cdbf1308e202.png)

I feel like I am missing something here, but I am not sure what I did incorrectly. Any advice on how to randomize two columns in the same loop in a way that also works online?

Thank you so much in advance!

---

<div class="post-metadata">

**Author:** ![Jun\_Fang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jun_fang/32/35952_2.png) [@Jun\_Fang](https://discourse.psychopy.org/u/Jun_Fang)\
**Post date:** [January 13, 2024, 2:28am UTC](https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193/2 "2024-01-13T02:28:20Z")

</div>

After getting your experiment up and running locally (in python), you need to convert the python code to Javascript so that it runs online. PsychoPy has this amazing auto ‘translator’ turn python to JS for you. But it is not perfect, you probably will need to go through a debugging process. You can open your browser console to read what your program complains about.

For example, your num\_item variable is not defined. JS has different scope for variables (compared to python), the variables defined within a function won’t be readable globally. That may be the reason why your local python program works but JS doesn’t.

You may find this link helpful [PsychoPy Python to Javascript crib sheet](https://discourse.psychopy.org/t/psychopy-python-to-javascript-crib-sheet/14601)

---

<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 13, 2024, 7:48am UTC](https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193/3 "2024-01-13T07:48:27Z")

</div>

Try putting num\_items=0 in a Begin Experiment tab if a code component.

---

<div class="post-metadata">

**Author:** ![H\_B](https://avatars.discourse-cdn.com/v4/letter/h/ba8739/32.png) [@H\_B](https://discourse.psychopy.org/u/H_B)\
**Post date:** [January 16, 2024, 4:29pm UTC](https://discourse.psychopy.org/t/randomizing-two-lists-of-stimuli-within-a-single-loop-online/38193/4 "2024-01-16T16:29:40Z")

</div>

Thank you so much for the tip! I tried this, but it no longer ran locally. It did not give me an error, though. It just closed, as if the experiment had ended.

This is what the Builder looks like:

 ![Screenshot 2024-01-16 at 11.22.26 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/a/4a5d9484c5adad026f7f4cf5156a3bbe25ae2b1d.jpeg)

This is the “codeinit” code component:

 ![Screenshot 2024-01-16 at 11.21.47 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/4/b43b1d694e360403c4a987270826e82384b6c6b4.jpeg)  
 ![Screenshot 2024-01-16 at 11.22.09 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/4/c42bdcff47cfb9378c469162462a3d79c5d36267.jpeg)

Here is the second routine, and the associated code component and loop info:

 ![Screenshot 2024-01-16 at 11.22.39 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/6/e648093991310b494a8f2220c3af08eb5077244e.jpeg)  
 ![Screenshot 2024-01-16 at 11.22.49 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/f/df329cf075690b82080d5d3983d1f2834f672f58.jpeg)  
 ![Screenshot 2024-01-16 at 11.23.03 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/1/d10a114417f9374f248f6c4d51ec08b3c58b6f4f.png)  
 ![Screenshot 2024-01-16 at 11.23.11 AM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/f/7fa36ad699c1aefd316e6f76a9a0552727727aa6.jpeg)

Is anything jumping out at you?
