Creating a Distraction Attention Experiment

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!!

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:

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.

1 Like

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.

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:

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.

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?

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

1 Like

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

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

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.

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

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)

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.

1 Like

Here are the images and the file! Thank you!

ConditionsDA.xlsx (9.1 KB) DisAtten.psyexp (20.2 KB)

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.

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.

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!

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