# Feedback crashes my experiment

**URL:** <https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684>\
**Category:** Coding\
**Tags:** feedback\
**Created:** [November 2, 2022, 12:57pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684 "2022-11-02T12:57:14Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 12:57pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/1 "2022-11-02T12:57:14Z")

</div>

Hi, I am trying to provide feedback to participants for the picture-matching game. There are 36 questions with two options. In every 4 questions, I would like to provide accurate feedback.  
I don’t know how to do that, so I started with a simple step. I tried to provide feedback every trial, but it crashed my experiment. I would appreciate it if you could help me solve the problem with the code and give suggestions about providing feedback every 4 trials instead of giving feedback every trial.  
Here is my code.

This code is on the “end routine” of picture matching routine.

```auto
# correct response 
if l_image == correct:
    correct_response_image = "left_image"
elif r_image == correct:
      correct_response_image = "right_image"
# save the correct answers
if response_image == correct_response_image:
    thisExp.addData('corrAns', '1')
else:
    thisExp.addData('corrAns', '0')

```

This code is on the “begin routine” of the feedback routine

```auto
if(corrAns == 1):
    feedback_text = "Correct"
else:
    feedback_text = "Wrong"

```

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [November 2, 2022, 1:03pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/2 "2022-11-02T13:03:49Z")

</div>

What error message do you get when it crashes?

---

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 1:06pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/3 "2022-11-02T13:06:40Z")

</div>

it says:

Alert 4210:JavaScript Syntax Error in ‘Begin JS Experiment’ tab. See ‘Line 1: Unexpected token’ in the ‘Begin JS Experiment’ tab.  
For further info see [4210: Probable syntax error detected in your JavaScript code — PsychoPy v2022.2.4](https://psychopy.org/alerts/4210.html)

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 2, 2022, 1:37pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/4 "2022-11-02T13:37:19Z")

</div>

Are you trying to run this experiment online?

Do you have any Begin Experiment code components?

---

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 1:43pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/5 "2022-11-02T13:43:34Z")

</div>

No, the experiment is offline, but I will do the experiment online later.

I do not have Begin Experiment code in Picture Matching and Feedback Routine. However, in my last routine, there is a code on Begin Experiment to record videos of participants. The code is:

```auto
import numpy as np
import cv2 # this is the OpenCV library for computer vision
fourcc = cv2.VideoWriter_fourcc(*'XVID')
#out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
print(expInfo['participant'])
out = cv2.VideoWriter(expInfo['participant'] + '_output.avi', fourcc, 20.0, (640, 480))
webCam = cv2.VideoCapture(0) # connect to the zeroth video camera

```

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [November 2, 2022, 1:46pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/6 "2022-11-02T13:46:21Z")

</div>

You can’t import numpy (or cv2) online. I think that the error message is about the JavaScript, and unrelated to your offline crash. Are there any other error messages?

---

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 1:54pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/7 "2022-11-02T13:54:38Z")

</div>

> NameError: name ‘corrAns’ is not defined  
> [WARN:0] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap\_msmf.cpp (438) `anonymous-namespace’::SourceReaderCB::~SourceReaderCB terminating async callback  
> 22.9878 WARNING 0.6639703999971971: Video catchup needed, advancing self.\_nextFrameT from 0.0 to 0.03336666666666667  
> 22.9878 WARNING 0.6640094999966095: Video catchup needed, advancing self.\_nextFrameT from 0.03336666666666667 to 0.06673333333333334  
> 22.9878 WARNING 0.6640270999996574: Video catchup needed, advancing self.\_nextFrameT from 0.06673333333333334 to 0.10010000000000001  
> 22.9879 WARNING 0.6640428000027896: Video catchup needed, advancing self.\_nextFrameT from 0.10010000000000001 to 0.13346666666666668  
> 22.9879 WARNING 0.6640636000011: Video catchup needed, advancing self.\_nextFrameT from 0.13346666666666668 to 0.16683333333333333  
> 22.9879 WARNING 0.6640791999961948: Video catchup needed, advancing self.\_nextFrameT from 0.16683333333333333 to 0.2002  
> 22.9879 WARNING 0.6640922000005958: Video catchup needed, advancing self.\_nextFrameT from 0.2002 to 0.23356666666666664  
> 22.9879 WARNING 0.6641039000023738: Video catchup needed, advancing self.\_nextFrameT from 0.23356666666666664 to 0.2669333333333333  
> 22.9879 WARNING 0.6641157999983989: Video catchup needed, advancing self.\_nextFrameT from 0.2669333333333333 to 0.30029999999999996  
> 22.9879 WARNING 0.6641278000024613: Video catchup needed, advancing self.\_nextFrameT from 0.30029999999999996 to 0.3336666666666666  
> 22.9879 WARNING Max reportNDroppedFrames reached, will not log any more dropped frames  
> 1.1048 WARNING Monitor specification not found. Creating a temporary one…  
> ################# Experiment ended with exit code 1 [pid:7916] #################  
> 4169.9774 EXP Imported picture\_matching\_images.xlsx as conditions, 7 conditions, 6 params  
> 4169.9795 INFO Loaded monitor calibration from [‘2022\_04\_29 09:14’]

---

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 1:56pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/8 "2022-11-02T13:56:49Z")

</div>

It says corrAns is not defined but I defined it like this:

```auto
# save the correct answers
if response_image == correct_response_image:
    thisExp.addData('corrAns', '1')
else:
    thisExp.addData('corrAns', '0')

```

and I can see it in my excel file

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [November 2, 2022, 2:55pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/9 "2022-11-02T14:55:14Z")

</div>

Adding a column to the data file doesn’t define a variable within the experiment, I think what you want is more like this:

```auto
if response_image == correct_response_image:
    corrAns =1
else:
    corrAns = 0
thisExp.addData('corrAns', corrAns)

```

---

<div class="post-metadata">

**Author:** ![eylul4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/eylul4/32/36075_2.png) [@eylul4](https://discourse.psychopy.org/u/eylul4)\
**Post date:** [November 2, 2022, 3:32pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/10 "2022-11-02T15:32:37Z")

</div>

It works now, thank you! I am trying to give feedback every 4 trials instead of giving feedback every trial. Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [November 2, 2022, 4:06pm UTC](https://discourse.psychopy.org/t/feedback-crashes-my-experiment/31684/11 "2022-11-02T16:06:20Z")

</div>

You could put the feedback routine in a loop whose `nRepeats` is `not bool(trials.thisN % 4)`? That way if there’s any remainder when dividing the trial number by 4, the feedback routine is skipped (as nRepeats is 0)
