Please help me, how to record accuracy responses in this task!

windows 7**
PsychoPy version 1.83
Im trying to develop a task where there will be a background grid of four rectangle boxes, an image will appear in one of the rectangular boxes. I have used 8 images and inserted condition for the experiment trials. As I said earlier, out of 8 images, one image will appear on one of the rectangular boxes. Participant needs to click mouse against the target image which appears on the respective rectangular box. I have written the code like this. But the responses are not getting recorded accurately.

Begin experiment:
a_sound = sound.Sound('A1.wav')
b_sound = sound.Sound('B1.wav')

items=0
right=0
wrong=0

Each frame:
for stimulus in [image11, image22,image33,image44,image55,image66,image77,image88]:

        # check if the mouse is pressed within the current one:
        if mouse.isPressedIn(stimulus):
            thisExp.addData('items', 1)
            items=items+1

            # Yes, so store the reaction time in the data
            thisExp.addData('RT', t)

            # check if the stimulus' image filename matches the correct answer:
            if stimulus.image == corrAns:
                a_sound.play()
                thisExp.addData('acc', 1)
                right=right+1
            else:
                 b_sound.play()
                 thisExp.addData('acc', 0)
                 thisExp.addData('wrong', 1)
                 wrong=wrong+1
            continueRoutine = False 
            # end the trial once done here:

Please help me.
Thank you in advance.!
builderview|690x255

Hi @Darshan_H.S, so what are you having recorded for accuracy? Also, perhaps you could add some print statements to see what is happening. E.g.,

if stimulus.image == corrAns:
    print("Correct. Image = %s corrAns = %s" % (stimulus.image, corrAns))
    a_sound.play()
    thisExp.addData('acc', 1)
    right=right+1
else:
    print("Incorrect. Image = %s corrAns = %s" % (stimulus.image, corrAns))
    b_sound.play()
    thisExp.addData('acc', 0)
    thisExp.addData('wrong', 1)
    wrong=wrong+1

@dvbridges , Hi sir, Thankyou for your precious time.
I wanted to record accuracy responses. Instead incorrect responses are being recorded. I ran the test on myself. I gave the responses correctly , still it isnt recording properly. And, reaction time for the same responses are recorded correctly.
For the four rectangular boxes on the grid placed , there are eight images appears one at a time. All eight images are put on the builder view, opacity is set for all the images and each image appears based on the condition which is set. Is because of this, responses are not stored correctly??

Thanks, well lets try the print statements above, and see why your stim image names are not the same as corrAns. Please run the study with my additional code, copy the output and paste it here.

@dvbridges Thank-you so much sir,
I will get back to you.

HIii sir…I ran the study using your additional code and here is the output of it. Now RT isn’t getting recorded.

This was my earlier output ( which did not use your additional code)

Hi @Darshan_H.S, apologies, I meant that you should show me the outputs of the print statements. You only need to add the print statements from the code. Then, at the end of the task, or after you press escape, the printed outputs should appear in the dialog box that appears.

SIr, I apologize you. I couldnt understand what u said. Im new to Psychopy. Sorry sir.

The reason for not naming the stimulus image names as to corrAns, is that the same stimuli are used in another routine in the task. So i did not name the stimuli in the builder view.
This is the output statement

@Darshan_H.S, so the iamge you have shown me shows that the first and last of your responses were correct, but all other responses were incorrect, because the stimulus name e.g., B.jpg did not match the image name stored in corrAns e.g., A.jpg. Is this the expected behaviour?


Sir, This is how my condition file looks like.

Hello @Darshan_H.S ,

your code and the output look fine to me so far. Please be very precise about what behavior should happen and what exactly happens so that we can understand what goes wrong.

After you click on an image, should the trial proceed with the next picture regardless whether you are correct or incorrect? I don’t understand what are you trying to achieve with continueRoutine = False which is only called if a stimulus has been clicked in the current frame?
From my intuition about what is your goal, you might want this:

Each frame:
continueRoutine = False #this is new
for stimulus in [image11, image22,image33,image44,image55,image66,image77,image88]:

        # check if the mouse is pressed within the current one:
        if mouse.isPressedIn(stimulus):
            thisExp.addData('items', 1)
            items=items+1

            # Yes, so store the reaction time in the data
            thisExp.addData('RT', t)

            # check if the stimulus' image filename matches the correct answer:
            if stimulus.image == corrAns:
                a_sound.play()
                thisExp.addData('acc', 1)
                right=right+1
            else:
                 b_sound.play()
                 thisExp.addData('acc', 0)
                 thisExp.addData('wrong', 1)
                 wrong=wrong+1
            continueRoutine = True #Only continue if any stimulus has been clicked

Also, please be aware that it might be possible to click on the transparent images (you said: “opacity is set for all the images”) such that mouse.isPressedIn(stimulus) might return True even if the image is transparent at the moment. Since there are 8 images and only 4 boxes, I would expect that at least two images share one box. Therefore, it might be possible that ALL images within the same box will be interpreted as clicked in the same frame no matter if they are transparent or opaque. Maybe this causes some of the problems you experience. Instead of setting opacity, it might be better to manipulate whether they are drawn or not.

Hope this helps.
Mario

Thank you so much for your reply @mario.reutter. As you said, all 8 images within the 4 boxes will be interpreted as clicked in the same frame no matter if they are transparent or opaque.This is causing the problem.
Apart from setting opacity for stimulus. Is there any other way to access the stimulus images in the routine ??

Perfect! Finding the problem is the most important step in programming :slight_smile:

Every stimulus has a function called draw that needs to be called in order for the stimulus to be put on screen after the current window gets a call to its flip function. It seems like at the beginning of the trial this function is called for all 8 stimuli. This needs to be disabled. Additionally, instead of setting stimulus.opacity = 1 you need to call stimulus.draw() for all stimuli that have received opacity of 1 before (and simply do nothing for images that should be “transparent”).

Best regards,
Mario

1 Like

Thankyou sir @mario.reutter… For the present experiment, I changed the stimuli itself and its conditions.
I shall incorporate these valuable inputs of yours in my future psychopy experiments.
Thank you sir once again for your precious time! :slight_smile: