# Changing rows in conditions file dynamically within loop

**URL:** <https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540>\
**Category:** Builder\
**Created:** [June 10, 2022, 1:10am UTC](https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540 "2022-06-10T01:10:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thouser](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@thouser](https://discourse.psychopy.org/u/thouser)\
**Post date:** [June 10, 2022, 1:10am UTC](https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540/1 "2022-06-10T01:10:49Z")

</div>

Hello,  
I am trying to select rows from a conditions file dynamically. I also want to dynamically select rows within a single loop.

So, I tried 1 loop, setting the trialProperties Selected row component to a variable ($selectedRow). The variable depends on the response made for each routine.

```auto
selectedRow = str(choice-1)+':'+str(choice)

```

Begin Experiment:

```auto
choice = 1

```

End routine:

```auto
if key_resp.keys == '1':
    choice = n1node
if key_resp.keys == '2':
    choice = n2node

```

n1node and n2node are stimuli.

On the next loop, instead of showing the updated choice (n1node or n2node), the previous stimulus is shown again. Any help is appreciated!!

---

<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 10, 2022, 5:29am UTC](https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540/2 "2022-06-10T05:29:07Z")

</div>

You can’t change the selected rows once a loop has started. However, you could do it with two concentric loops. Put a Routine in the outer loop (after the inner loop) which sets the selected row for the inner loop (or breaks the outer loop if the task has finished)

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [June 10, 2022, 12:34pm UTC](https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540/3 "2022-06-10T12:34:40Z")

</div>

As @wakecarter mentioned, you can’t do this out of box. But you can manipulate trials by understanding that “under the hood” a spreadsheet is imported to psychopy as a list of dictionaries. You can make custom trial lists through manipulating that list of dictionaries. It is a bit more involved but here is a [tutorial](https://workshops.psychopy.org/3days/day3/builder_parallel/customRandomisation.html) we run in our workshops in this topic.

Hopefully this is helpful,  
Becca

---

<div class="post-metadata">

**Author:** ![thouser](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@thouser](https://discourse.psychopy.org/u/thouser)\
**Post date:** [June 16, 2022, 9:09pm UTC](https://discourse.psychopy.org/t/changing-rows-in-conditions-file-dynamically-within-loop/29540/4 "2022-06-16T21:09:57Z")

</div>

Very helpful–thank you!
