# Implement different tasks based on session which is written before the running

**URL:** https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932
**Category:** Builder
**Created:** [March 3, 2024, 9:00am UTC](https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932 "2024-03-03T09:00:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Julien](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/julien/32/41025_2.png) [@Julien](https://discourse.psychopy.org/u/Julien)
#### Post date: [March 3, 2024, 9:00am UTC](https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932/1 "2024-03-03T09:00:34Z")

</div>

OS: Win11  
PsychoPy version : PsychoPy 2023.2.3

My purpose：

1. Design 4 loops, each containing 30 trials, each trial runs the same program but presents different stimuli.
2. The 120 trials, which could have been combined into a single loop, are divided into 4 loops due to participant breaks interspersed between them.

My issue：

1. Participants may exit midway through the experiment, causing subsequent trials to restart from the beginning.
2. I want to use the session provided at the beginning to determine which loop of the trial the participant has left to complete.

What I have done:  
 ![1709455800439](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/2/f20e08c2cdf71045b5004e34034c0147200d6697.png)  
 ![1709456408057](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/6/66f45951e18893d6a6f35f1fa3a3c4f338921c3d.png)

as you can see, I intend to assign a Block\_number for each loop, which will be toggled 0/1 based on the session identifier. Consequently, at the beginning of each loop, I can check whether to proceed based on the Block\_number value.

But this cannot work, the program is running as if I hadn’t set any code yet. By the way, I’ve successfully run each loop. I just want to use a control to confirm whether the loop should be executed or not.

So is there any solution or is there a simpler and more efficient way for me to achieve this task?

I’m new to PsychoPy and this forum, so I appreciate any help I can get. 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 3, 2024, 1:07pm UTC](https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932/2 "2024-03-03T13:07:10Z")

</div>

Which tab have you used? It should be Begin Experiment

---

<div class="post-metadata">

### Author: ![Julien](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/julien/32/41025_2.png) [@Julien](https://discourse.psychopy.org/u/Julien)
#### Post date: [March 4, 2024, 2:10pm UTC](https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932/3 "2024-03-04T14:10:03Z")

</div>

Do I have to put all the code inside ‘Begin Experiment’?

I asked some people, and the response I got was that I can achieve my idea by using code [\<loop\_name\>.finished = True (Python offline, replace \<loop\_name\> to the current loop name) and trials.finished = true (JS online)]

It’s more complex than I anticipated. I feel like this feature doesn’t require overly complicated statements.

---

<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 4, 2024, 2:50pm UTC](https://discourse.psychopy.org/t/implement-different-tasks-based-on-session-which-is-written-before-the-running/38932/5 "2024-03-04T14:50:45Z")

</div>

> [@Julien](#):
>
> I asked some people, and the response I got was that I can achieve my idea by using code [\<loop\_name\>.finished = True (Python offline, replace \<loop\_name\> to the current loop name) and trials.finished = true (JS online)]

It would be better to use nReps to stop the loop starting. trials.finished = True is for ending a loop early
