# Nested Loops not working Pavlovia

**URL:** <https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369>\
**Category:** Online experiments\
**Created:** [March 16, 2021, 2:39pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369 "2021-03-16T14:39:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![verdi](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@verdi](https://discourse.psychopy.org/u/verdi)\
**Post date:** [March 16, 2021, 2:39pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369/1 "2021-03-16T14:39:43Z")

</div>

I was wondering if anyone has got nested loops to work in Pavlovia? I’ve seen a few posts saying people have had difficulties, and I had the same thing (worked fine locally, but got a ‘Javascript error’ when working on Pavlovia).

It would be great to know if it’s possible 🙂

Thanks in advance 🙂

---

<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 16, 2021, 4:46pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369/2 "2021-03-16T16:46:17Z")

</div>

I use nested loops quite often.

Are you trying to use .thisN?

---

<div class="post-metadata">

**Author:** ![verdi](https://avatars.discourse-cdn.com/v4/letter/v/b38774/32.png) [@verdi](https://discourse.psychopy.org/u/verdi)\
**Post date:** [March 16, 2021, 5:23pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369/3 "2021-03-16T17:23:01Z")

</div>

Thanks for your response! I apologise - the problem turned out to be something completely different which I’ve now fixed. (If this helps anyone, it was that I was using variables named ‘image’ and ‘sound’ which seems to work in the Python but not JS version).

I actually now have another problem with converting from Psychopy to JS. I’m trying to put in a stimulus which appears for a variable duration. To do this, I’m defining a variable at the beginning for the duration called ‘intertrialint’, and will ultimately want to set this to a changing value each repeat of the routine.  
However, while I can pass the ‘intertrialint’ variable into the ‘duration’ part of the stimulus in Psychopy (Python), when I try to run this online (with JS) it says ’ **ReferenceError: asarray is not defined** ’.  
Having looked at the JS version of the script, this seems to be because in the Python version it has a line saying ‘from numpy import … asarray’  
whereas in the JS version it just skips to asarray being used, in the line:

frameRemains = 1.0 + asarray(intertrialint) - psychoJS.window.monitorFramePeriod \* 0.75; // most of one frame period left

Do you know why this is, why the possibility of changing this variable is not passing to Javascript?

My experiment is: [SequenceTask1 [PsychoPy]](https://run.pavlovia.org/noxlab/seqtask1/)

Thanks so much 🙂

---

<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 16, 2021, 8:04pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369/4 "2021-03-16T20:04:46Z")

</div>

I’ll add image to my crib sheet list

**Variable names to avoid are: core, index, Object, Length, Number, round, sound, Symbol, t, thisTrial, trials, util, visual.**

---

<div class="post-metadata">

**Author:** ![thomas\_pronk](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/thomas_pronk/32/9531_2.png) [@thomas\_pronk](https://discourse.psychopy.org/u/thomas_pronk)\
**Post date:** [March 16, 2021, 8:12pm UTC](https://discourse.psychopy.org/t/nested-loops-not-working-pavlovia/21369/5 "2021-03-16T20:12:46Z")

</div>

About the asarray problem. In another thread I’ve got a little pointer that might help? [Error message: asarray not defined - #3 by thomas\_pronk](https://discourse.psychopy.org/t/error-message-asarray-not-defined/20996/3)
