# Switching between different routines (subtasks) after one trial each

**URL:** <https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869>\
**Category:** Builder\
**Tags:** randomization\
**Created:** [November 9, 2021, 11:30am UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869 "2021-11-09T11:30:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuisaBogenschuetz](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@LuisaBogenschuetz](https://discourse.psychopy.org/u/LuisaBogenschuetz)\
**Post date:** [November 9, 2021, 11:30am UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/1 "2021-11-09T11:30:30Z")

</div>

**OS** (e.g. Win10): Win10  
**PsychoPy version** (e.g. 1.84.x): PsychoPy 2021.2.3  
**Standard Standalone? (y/n)** : yes  
**What are you trying to achieve?:** I want to present to present odors, pictures and words to participants in a random order.

 ![grafik](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/a/7adc16287673fce6bda73a2d786516a438363dc1.png)

**What did you try to make it work?:** I have created an experiment with three loops controlling each stimulus type. I want to present 8 odors, 8 words and 8 pictures in random order. I have created an outerloop to randomize the order of the subtasks. My problem is that I only want to present one trial of each stimulus per outerloop. Essentially, I want psychopy to go through an show one odor, one word and one picture in random order in each iteration.  
I have tried to implement a counter.

Begin Experiment: loop\_number=0  
Begin Routine: loop\_number=+1

And I for each stimulus type in the loop I added Selected Row: $(loop\_number-1)

**What specifically went wrong when you tried that?:**  
This is the error code:  
File “C:\Users\Luisa\Documents\PhD\Experiments\vAM\_1week\v\_AM\_1week\_lastrun.py”, line 282, in   
trialList=data.importConditions(‘stim\_pictures.xlsx’, selection=(loop\_number-1)),  
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\data\utils.py”, line 470, in importConditions  
elif len(selection) \> 0:  
TypeError: object of type ‘int’ has no len()

I can’t seem to find a similiar topic, which really surprises me. Thank you in advance!

---

<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:** [November 10, 2021, 11:48am UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/2 "2021-11-10T11:48:25Z")

</div>

Hi There,

This looks the right direction to me - what does the conditions file provided to your outermost loop look like? If you only want one of the inner loops to be presented per trial then it should loop something like:

| repA | repB | repC | trialype |
| --- | --- | --- | --- |
| 0 | 0 | 1 | odorTrial |
| 0 | 1 | 0 | wordTrial |
| 1 | 0 | 0 | pictureTrial |

Where “repA” is used in the nReps firls of your first loop, repB for the second loop and repC for the third.

Hope this helps,  
Becca

---

<div class="post-metadata">

**Author:** ![LuisaBogenschuetz](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@LuisaBogenschuetz](https://discourse.psychopy.org/u/LuisaBogenschuetz)\
**Post date:** [November 10, 2021, 11:51am UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/3 "2021-11-10T11:51:18Z")

</div>

Hi Becca,  
thank you so much for the reply!! Where would the trialtype variable come into play?

All the best,  
Luisa

---

<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:** [November 10, 2021, 4:22pm UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/4 "2021-11-10T16:22:32Z")

</div>

That variable is just a handy label (not used in the task but saved to the data file for future you!)

Becca

---

<div class="post-metadata">

**Author:** ![LuisaBogenschuetz](https://avatars.discourse-cdn.com/v4/letter/l/da6949/32.png) [@LuisaBogenschuetz](https://discourse.psychopy.org/u/LuisaBogenschuetz)\
**Post date:** [November 11, 2021, 3:51pm UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/5 "2021-11-11T15:51:21Z")

</div>

This doesn’t work for me unfortunately. It randomizes the order of the stimuli blocks but it doesn’t only show one trial.

---

<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:** [November 12, 2021, 7:34pm UTC](https://discourse.psychopy.org/t/switching-between-different-routines-subtasks-after-one-trial-each/25869/6 "2021-11-12T19:34:41Z")

</div>

Are you also feeding in a conditions file to each of the inner loops? because if so make sure that you do not have spreadsheets in the inner loops - only one spreadsheet in the outer loop
