# Setting the selected rows with a changing variable

**URL:** <https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123>\
**Category:** Online experiments\
**Tags:** pavlovia\
**Created:** [October 8, 2020, 3:50pm UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123 "2020-10-08T15:50:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gal\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gal_chen/32/8243_2.png) [@Gal\_Chen](https://discourse.psychopy.org/u/Gal_Chen)\
**Post date:** [October 8, 2020, 3:50pm UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/1 "2020-10-08T15:50:21Z")

</div>

URL of experiment:

> **[Pavlovia](https://pavlovia.org/GalChen/hwl_03_09_20)**
>
> The place for the wide community of researchers in the behavioural sciences to run, share, and explore experiments online

Description of the problem:  
Hello all. I’m now about to finish building my first experiment using Pavlovia, and I have a problem that I am not sure how to debug since it’s online.

I am trying to set one of my loops to start in a different row in any iterations. The loop stops after K repetitions, when K is the number of loops until the subject response. (it sounds stimulus 0, stimulus 1, stimulus 2, 3 until response) so I don’t know exactly when will the next loop will start. I want to make it start in stimulus K, so if the subject heard stimuli 0-4 he will now hear stimulus 5.

I’ve set a counter called “bad\_count” and the syntax there seems to be OK so it increases in 1 each time the routines in the loop end (I’ve saved it in the log to make sure it happens). However, when I write in the selected rows “(USD sign)bad\_count:55” I get a syntax error (“Initializing the experiment…”). I tried to remove the $ sign and the experiment runs but always starts the loop from row 0.

how do I get it to address a different starting point for the selected rows each time I loop?

EDIT: for some reason I can’t show the USD sign used to mark code. Now it appears…

Thanks a lot

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/8/a8c6ee66e8ad1814eb3160056ad7cf17d6a97f57.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 8, 2020, 9:29pm UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/2 "2020-10-08T21:29:00Z")

</div>

Try putting a `$` prefix there to indicate that this is a code expression and a not a literal value:

```
$bad_count:55

```

Note that the labels for the fields in this dialog vary in whether they contain a `$` (indicating that the field defaults to expecting a non-literal value) or not. The “Selected rows” field does not have one, so you need to specify it when required.

---

<div class="post-metadata">

**Author:** ![TimCottier](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TimCottier](https://discourse.psychopy.org/u/TimCottier)\
**Post date:** [October 9, 2020, 2:32am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/3 "2020-10-09T02:32:01Z")

</div>

Unfortunately, when I try to put a variable in my Selected Rows I get a syntax error. Is this normal?

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/2/b25a83bf092c7b884da4f2f58ea22f2d030fdee5.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 9, 2020, 2:49am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/4 "2020-10-09T02:49:44Z")

</div>

As suggested above, the `$` goes at the start: it applies to the whole expression, rather than one element of it.

---

<div class="post-metadata">

**Author:** ![TimCottier](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TimCottier](https://discourse.psychopy.org/u/TimCottier)\
**Post date:** [October 9, 2020, 3:06am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/5 "2020-10-09T03:06:58Z")

</div>

Thanks for the speedy reply Michael! Unfortunately, I am still getting the python syntax error across multiple loops:

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/f/5f380df1d4efd3ac705f58a13fa48278a9151885.png)

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/d/7/d7422cf0da8e2e19423072bee297b6fb09ddccfc.png)

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 9, 2020, 3:28am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/6 "2020-10-09T03:28:46Z")

</div>

Something has just gotten a little pathological for you. The only way I can replicate something like this is to intentionally put in a syntax error, leading to the red error message, and then correct it. But the error message remains, so one needs to push “cancel” and try again.

If cancelling doesn’t work, I’d then suggest simply deleting the loop and reinserting it.

Otherwise, push the “compile script” button and look for the block of code that starts like:

```
name_of_your_loop = data.TrialHandler( 

```

and copy and paste the entire contents of that function call here for us to see.

---

<div class="post-metadata">

**Author:** ![TimCottier](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@TimCottier](https://discourse.psychopy.org/u/TimCottier)\
**Post date:** [October 9, 2020, 4:12am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/7 "2020-10-09T04:12:43Z")

</div>

> [@Michael](#):
>
> `$bad_count:55`

Thanks for your tips and assistance Michael!

Cancelling didn’t fix it unfortunately. I tried deleting the loops and reinserting them, that also didn’t fix the issue.  
I even created a new builder experiment, recreating just two components, however, the loop still has the same issue.

I found that $SelectRows:10 will work, but $0:SelectRows won’t work for whatever reason. I managed to fix the syntax error by creating a new variable in a code component that = 0, and putting that as the first value in my index ($NewVariable:SelectRow).

---

<div class="post-metadata">

**Author:** ![Gal\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gal_chen/32/8243_2.png) [@Gal\_Chen](https://discourse.psychopy.org/u/Gal_Chen)\
**Post date:** [October 9, 2020, 9:50am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/8 "2020-10-09T09:50:15Z")

</div>

Thank you for the assistance!  
The $ sign doesn’t help. also setting both ending and start of loop as variable var1:var2 doesn;t help. with the sign i get a syntax error (stuck “initializing…”) and without it I just get a regular loop for 0 to the end.

Is there something in my code specifically that made this happen? I tried to move this part of the code to the begining of the routine or it’s ending but it doesnt help. I also tried to save it in my log file that i download from pavlovia and I see that it **does** add 1 to the counter each time and in the right places. so my conclusion here is that there is something in the “selected rows” arguement itself that caused the error. here is the JS implementation of it:

> trials\_bad\_catch = new TrialHandler({  
> psychoJS: psychoJS,  
> nReps: probe\_salient, method: TrialHandler.Method.SEQUENTIAL,  
> extraInfo: expInfo, originPath: undefined,  
> trialList: TrialHandler.importConditions(psychoJS.serverManager, ‘trials\_pod\_bad.csv’, bad\_count: end\_bad\_loop),  
> seed: undefined, name: ‘trials\_bad\_catch’  
> });

I suspect that for some reason the saved variables from other routines are not being saved and as a result the variables are not defined.

Thank you for any assistance you could provide - really appreciated.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/b/fb8800d925fa6aedd1b7fef53df75fed7377a52e.png)

![image](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/8/4801eedd446aa99c002d1a1785d1c421bc6741ae.png)

---

<div class="post-metadata">

**Author:** ![abarnas](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@abarnas](https://discourse.psychopy.org/u/abarnas)\
**Post date:** [July 18, 2021, 4:00am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/9 "2021-07-18T04:00:50Z")

</div>

Hi @Gal_Chen

Were you able to figure out this issue?

---

<div class="post-metadata">

**Author:** ![Gal\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/gal_chen/32/8243_2.png) [@Gal\_Chen](https://discourse.psychopy.org/u/Gal_Chen)\
**Post date:** [July 18, 2021, 5:31am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/10 "2021-07-18T05:31:54Z")

</div>

Hi - We are 9 months and 100 bugs later, so I am having trouble to remember whats going on here. The final version I have used doesn’t look like that, so I tend think I gave up on this issue and did something else.

בתאריך יום א׳, 18 ביולי 2021, 07:10, מאת Adam B via PsychoPy ‏\<[psychopy@discoursemail.com](mailto:psychopy@discoursemail.com)\>:

---

<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:** [July 18, 2021, 10:13am UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/11 "2021-07-18T10:13:33Z")

</div>

bad\_count:end\_loop needs to be a string. I would set in code

```auto
useRows = str(bad_count) + “:” + str(end_loop+1)

```

and then put $useRows in the loop.

---

<div class="post-metadata">

**Author:** ![Laurie\_Geers](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/laurie_geers/32/5918_2.png) [@Laurie\_Geers](https://discourse.psychopy.org/u/Laurie_Geers)\
**Post date:** [May 15, 2022, 8:34pm UTC](https://discourse.psychopy.org/t/setting-the-selected-rows-with-a-changing-variable/17123/12 "2022-05-15T20:34:06Z")

</div>

Worked for me, thanks !
