# Creating a Distraction Attention Experiment

**URL:** <https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825>\
**Category:** Builder\
**Tags:** randomization\
**Created:** [November 10, 2019, 6:52pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825 "2019-11-10T18:52:31Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 10, 2019, 6:52pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/1 "2019-11-10T18:52:31Z")

</div>

Hi! I am very new to psychopy and have been watching the videos about the basics. I wanted to create an experiment for my class and I need some help on making the experiment. I wanted to create an experiment where the subjects would have to answer questions that are basic arithmetic. I need a few distractors randomized into the experiment so when they are working out the equation they have distractors present in some trials. I am testing for accuracy and reaction time.

I am not sure how to set this up in terms of data. I have found videos on youtube that explain that having my data in an excel file would be able to do that. Data meaning the questions I want to ask. I am not sure if this is the most convenient way to go about it. Sorry if this all sounds so simple. I am really new and haven’t built psychopy experiments.

You tips and tricks are very welcomed. Also, I am running the 1.82.01 version of psychopy on my Mac laptop with Mojave. I was told not to update psychopy for our specific class because the other versions are not compatible with the experiments we were told to run. 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:** [November 10, 2019, 9:58pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/2 "2019-11-10T21:58:34Z")

</div>

Yes, you should put your questions in a conditions file, but also have a column that indicates whether this trial will have a distractor, something like:

```auto
question answer distractor
2 × 3 6 False
5 × 6 30 False
9 × 4 36 True
2 × 5 10 True

```

You can do different things in a trial based on the value of the `distractor` variable, but we would need to know more about your task to be more specific.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 10, 2019, 11:41pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/3 "2019-11-10T23:41:13Z")

</div>

Thank you!

So for the distractor variables, there would be distractor sounds and images. I was struggling with how to randomize the sounds and images for the trials. I have gotten my conditions file set and uploaded. The only thing I need to add now is distractors.

---

<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:** [November 11, 2019, 3:56am UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/4 "2019-11-11T03:56:57Z")

</div>

OK, so the easiest thing to do here is put “none” in the conditions file for trials where you don’t want to have a sound or image file used:

```auto
question answer distractor sound_file image_file
2 × 3 6 True woof.wav dog.jpg
5 × 6 30 True miaow.wav cat.jpg
2 × 3 6 False None None
5 × 6 30 False None None
etc

```

In the case above, the “distractor” variable isn’t actually being used, it will just appear in the data file for informational purposes in your analysis.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 16, 2019, 11:28pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/5 "2019-11-16T23:28:12Z")

</div>

Hi Michael!

Thank you very much. I was wondering how to add the sound file in psychopy that is attached to the “true” distractors. As in how can i add the sound files in psychopy builder for the distractors equation?

---

<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:** [November 17, 2019, 12:50am UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/6 "2019-11-17T00:50:40Z")

</div>

You insert a sound component and put `$sound_file` (or whatever column name you are using) in its “sound” field, and set it to “set every repeat” rather than be “constant”.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 17, 2019, 7:25pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/7 "2019-11-17T19:25:27Z")

</div>

Hmm, I tried that but i get this error code:

AttributeError: ‘unicode’ object has no attribute ‘setSound’

---

<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:** [November 17, 2019, 8:12pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/8 "2019-11-17T20:12:18Z")

</div>

Somewhere you must have some custom code that is overwriting the name of your sound component, or you are using the name of your sound component as one of the columns in your conditions file. Everything needs to have a unique name to avoid issues like this.

Check your conditions file first, and if no joy there, then please show us any custom code you might be using.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 17, 2019, 8:55pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/9 "2019-11-17T20:55:08Z")

</div>

This is the only code i am using and also the column in my conditions file for sounds is labeled sound\_file but the actual file for the sound is called beep.wav

```auto
if ("backspace" in key_resp_Feedback.keys):
    key_resp_Feedback.keys.remove("backspace")
    
    if(len(key_resp_Feedback.keys) > 0):
        key_resp_Feedback.keys.pop()
elif("return" in key_resp_Feedback.keys):
    key_resp_Feedback.keys.remove("return")
    

    thisExp.addData("resp.accuracy", correct)
    thisExp.addData("resp.responseTime", t)
    
screen_text = ''.join(key_resp_Feedback.keys)

```

---

<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:** [November 17, 2019, 9:36pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/10 "2019-11-17T21:36:39Z")

</div>

OK, I think we need to see your entire error message, not just this line:

```
AttributeError: ‘unicode’ object has no attribute ‘setSound’

```

Also, your should probably post your .psyexp and conditions file.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 17, 2019, 9:46pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/11 "2019-11-17T21:46:42Z")

</div>

Here are the images and the file! Thank you!

 ![40%20PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/e/fe24ada96af77679a4d73933f5cfbd096011b679.jpeg)

[ConditionsDA.xlsx](https://discourse.psychopy.org/uploads/short-url/uCnMg7RRkLJWTITBXcameEGn30J.xlsx) (9.1 KB) [DisAtten.psyexp](https://discourse.psychopy.org/uploads/short-url/5TOUAHnDhL0eUN20NvYnDM05tn0.psyexp) (20.2 KB)

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 17, 2019, 9:57pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/12 "2019-11-17T21:57:01Z")

</div>

i should mention that my version of psychopy is 1.81.01. For class, i am not allowed to update so it has been rough figuring this out when most solutions have the latest updates.

---

<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:** [November 18, 2019, 2:54am UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/13 "2019-11-18T02:54:42Z")

</div>

As guessed above, and as shown in your screen shot, your sound component on the `Trial` routine is called `sound_file`, and so is a column in your conditions file. All such names need to be unique, otherwise the experiment code will get confused as to which one you are referring to.

---

<div class="post-metadata">

**Author:** ![Zobyedh\_Rahami](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/zobyedh_rahami/32/6227_2.png) [@Zobyedh\_Rahami](https://discourse.psychopy.org/u/Zobyedh_Rahami)\
**Post date:** [November 18, 2019, 3:00am UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/14 "2019-11-18T03:00:26Z")

</div>

I did realize that later on but now I am getting this message. Adding the distractor has really been the only issue for me and I can’t figure out why. I do appreciate your help!

 ![40%20PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/9/9/99cb53d36c671e16bc5d619e03adfbe2d6cd00c4.jpeg)

---

<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:** [November 18, 2019, 8:51pm UTC](https://discourse.psychopy.org/t/creating-a-distraction-attention-experiment/9825/15 "2019-11-18T20:51:04Z")

</div>

I _think_ the `None` values in your conditions file need an initial capital letter to get interpreted properly.
