# How to use a condition file in a feedback code (Builder)

**URL:** <https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397>\
**Category:** Builder\
**Created:** [October 14, 2019, 8:18pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397 "2019-10-14T20:18:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scuba](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Scuba](https://discourse.psychopy.org/u/Scuba)\
**Post date:** [October 14, 2019, 8:18pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397/1 "2019-10-14T20:18:13Z")

</div>

**OS** (e.g. Win8):  
**PsychoPy version** (3.2.4):  
\*\*Standard Standalone? (y):  
\*\*What are you trying to achieve?:

Im building a slider task, where participants are supposed to click in the middle (value = 50) of the slider. Since I want the Sliders to be in different positions on the screen, I use a conditions file with the first column “position”, which works perfectly fine, when using $position in the building of the slider.

My Problem is, that participants receive feedback about their mouse click (value 1-100 or invalid click (= “Bitte klicken Sie auf den Slider!”)). Since the valid positions of a click (x, y values) depend on the position of the according slider I use this conditions file with the columns (position, xlow, xhigh, ylow, yhigh, center) and use a piece of code in my feedback routine which looks as follow:

```auto
**Begin Routine**

X=trial_mouse_2.getPos() [0]
Y=trial_mouse_2.getPos() [1]
if X >= (trial_loop_2["xlow"]) and X <= (trial_loop_2["xhigh"]) and Y >= (trial_loop_2["ylow"]) and Y <= (trial_loop_2["yhigh"]):
    result = (trial_loop_2["center"]) + int(X * 100)
    msg = str(result)
else:
    msg = "Bitte klicken Sie auf den Slider!"

#I tried different codes, this code I got from an other forum discussion, but not about the exact same Problem I have.
#trial_loop_2 = Name of my loop, looping around the routine (polygon/mouse for slider & text/code for feedback)

**Error Message**
    if X >= (trial_loop_2["xlow"]) and X <= (trial_loop_2["xhigh"]) and Y >= (trial_loop_2["ylow"]) and Y <= (trial_loop_2["yhigh"]):
TypeError: 'TrialHandler' object is not subscriptable

```

So that is the Error Message I get every time. Unfortunately Google and this forum couldn’t help me out, about how the correct code to get the feedback output properly based on the conditions file should look like.

Hope somebody here can help me out. Would really appreciate any help. Thank you.

---

<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 14, 2019, 8:28pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397/2 "2019-10-14T20:28:38Z")

</div>

It seems like you’re trying to get the current value of a trial parameter by querying the TrialHandler object itself (which corresponds to a loop in Builder terms, and is a collection of trials), rather than specifically from the current trial from the TrialHandler.

Fortunately, Builder maintains the name `thisTrial` within each loop, which you can use for this purpose, so replace all expressions like `trial_loop_2["xlow"]` with `thisTrial["xlow"]` and so on.

---

<div class="post-metadata">

**Author:** ![Scuba](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Scuba](https://discourse.psychopy.org/u/Scuba)\
**Post date:** [October 14, 2019, 8:46pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397/3 "2019-10-14T20:46:12Z")

</div>

Thank you very much for you quick response, unfortunately this doesn’t seem to work either:  
(But anyhow a good point to remember for the future, thanks.)

**Error Message**

```auto
NameError: name 'thisTrial' is not defined
```

---

<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 14, 2019, 8:48pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397/4 "2019-10-14T20:48:56Z")

</div>

Sorry, the name will be specifically generated from the name of your particular loop, so use `thisTrial_loop_2`.

The variable names are probably also directly exposed for you by Builder, so you could be even more concise and just use the name `xlow` instead of the more explicit `thisTrial_loop_2["xlow"]`

---

<div class="post-metadata">

**Author:** ![Scuba](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@Scuba](https://discourse.psychopy.org/u/Scuba)\
**Post date:** [October 14, 2019, 9:26pm UTC](https://discourse.psychopy.org/t/how-to-use-a-condition-file-in-a-feedback-code-builder/9397/5 "2019-10-14T21:26:45Z")

</div>

Wow…I don’t know how to say it, but thank you so much…I tried almost everything, but never got the idea to just write `xlow` and so on. Which worked perfectly fine to give me the correct feedback. Thank you.
