Use Print statements
When debugging, print statements can be very helpful to track down errors or unexpected behaviour.
I tend to use them in one of two ways:
print('trial setup started')
Sometimes I won’t know where the error is, especially if there is a problem during the initial setup of the components or Begin experiment code. The components of each routine are set up in turn from top to bottom. Therefore, if you have a flow with routines called start, trial and finish and put print('trial setup started')
in the Begin experiment tab of a code component at the top of the trial routine then if the text appears in the Stdout tab of the PsychoPy Runner you know that the error isn’t in the setup of the start routine.
print('variableName',variableName)
If you have an error related to the value of a variable or unexpected behaviour due to, for example, an if statement always processing the default else code then the best option is to check the values of the relevant variables. You may discover that your key variable is undefined or is a list when you expected an integer.
A word of warning. Do not put print statements in the Each frame tab of a code component unless you do something to ensure that they aren’t being processed every frame. For example, one way of reducing a print statement to once per second is to use frameN:
if frameN % 60 == 0:
print('frame',frameN,'variableName',variableName)
Finally, if you want to be able to search the output of your print statements, copy and paste them into a text editor.