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

**URL:** https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634
**Category:** Coding
**Created:** [July 25, 2019, 2:09pm UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634 "2019-07-25T14:09:31Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 25, 2019, 2:09pm UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/1 "2019-07-25T14:09:31Z")

</div>

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.

```auto
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](https://discourse.psychopy.org/uploads/short-url/6R74NhPlBCXcxuHONiI0tQ2O3rk.png)

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [July 26, 2019, 8:25am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/2 "2019-07-26T08:25:13Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 26, 2019, 10:46am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/3 "2019-07-26T10:46:38Z")

</div>

@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??

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [July 26, 2019, 11:00am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/4 "2019-07-26T11:00:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 26, 2019, 11:32am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/5 "2019-07-26T11:32:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 27, 2019, 7:04am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/6 "2019-07-27T07:04:02Z")

</div>

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

 ![after%20incorporating%20your%20code](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/a/ca3bc6f3cdda04f04907209dcf4b7e1710a37f33.png)

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

 ![for%20my%20code](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/a/5a78e30722650adeb77e877666b60d3ab4416077.png)

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [July 27, 2019, 12:12pm UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/7 "2019-07-27T12:12:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 28, 2019, 2:45pm UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/8 "2019-07-28T14:45:40Z")

</div>

> [@dvbridges](#):
>
> 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

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

 ![output](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/f/5/f5253782233522d753747f7d6528ae27f66c2f9b.png)

---

<div class="post-metadata">

### Author: ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)
#### Post date: [July 29, 2019, 11:18am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/9 "2019-07-29T11:18:43Z")

</div>

@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?

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [July 29, 2019, 4:33pm UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/10 "2019-07-29T16:33:31Z")

</div>

![condition%20file](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/8/e87ef93201c3e2f52cd53c914e62d4c01c6509d3.png)  
Sir, This is how my condition file looks like.

---

<div class="post-metadata">

### Author: ![mario.reutter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/mario.reutter/32/5750_2.png) [@mario.reutter](https://discourse.psychopy.org/u/mario.reutter)
#### Post date: [August 1, 2019, 9:46am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/11 "2019-08-01T09:46:48Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [August 7, 2019, 10:49am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/12 "2019-08-07T10:49:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mario.reutter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/mario.reutter/32/5750_2.png) [@mario.reutter](https://discourse.psychopy.org/u/mario.reutter)
#### Post date: [August 7, 2019, 11:19am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/13 "2019-08-07T11:19:51Z")

</div>

Perfect! Finding the problem is the most important step in programming 🙂

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

---

<div class="post-metadata">

### Author: ![Darshan\_H.S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/darshan_h.s/32/4761_2.png) [@Darshan\_H.S](https://discourse.psychopy.org/u/Darshan_H.S)
#### Post date: [August 9, 2019, 10:42am UTC](https://discourse.psychopy.org/t/please-help-me-how-to-record-accuracy-responses-in-this-task/8634/14 "2019-08-09T10:42:46Z")

</div>

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