psychopy.org | Reference | Downloads | Github

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

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:

**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.

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.

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

NameError: name 'thisTrial' is not defined

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"]

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.