Giving feedback based on key presses

OS (e.g. Win10): OS 10.12.2
PsychoPy version (e.g. 1.84.x): 1.84.2

What are you trying to achieve?: I am trying to show one of two images based up whether or not a participant presses a button. So if they press any of 1-5 then they should see an image of coins right after, or if they don’t press any button they see an image with empty circles.

What did you try to make it work?: I have been trying to use a code component after the key response component. In the code component I have tried to have an if statement such as

if TwoGoGo1AllResponses.keys=='1' or TwoGoGo1AllResponses.keys=='2' or TwoGoGo1AllResponses.keys=='3' or TwoGoGo1AllResponses.keys=='4' or TwoGoGo1AllResponses.keys=='5':
     thisGo1Feedback = 'habitstimuli/penny.png'
else:
     thisGo1Feedback = 'habitstimuli/emptycircle.png'

What specifically went wrong when you tried that?: There is no error message but when I push the 1 button during the task for example, it does not show the penny image. It only shows the empty circle image regardless of what I press. I cannot figure out how to make an if statement that actually reads in what the button push was and then chooses the penny image when applicable.
Include pasted full error message if possible. “That didn’t work” is not enough information.

Now I am getting this error:

20.2449 	ERROR 	Couldn't make sense of requested image.
2017-04-23 19:15:13.249 python[42312:2786078] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/bm/94wgkc6s5_1gsmympsjrmddw0000gn/T/org.psychopy.PsychoPy2.savedState
Traceback (most recent call last):
  File "/myFilename.psy, line 1950, in <module>
    TwoGo_Go1Feedback.setImage(thisGo1Feedback)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/image.py", line 289, in setImage
    setAttribute(self, 'image', value, log)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/tools/attributetools.py", line 137, in setAttribute
    setattr(self, attrib, value)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/tools/attributetools.py", line 27, in __set__
    newValue = self.func(obj, value)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/image.py", line 276, in image
    forcePOW2=False)
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/visual/basevisual.py", line 808, in _createTexture
    raise AttributeError(msg)
AttributeError: Couldn't make sense of requested image.

You need to tell us more information. e.g.:

  • Where is this code?
  • what is thisGo1Feedback and where/how is it applied?

Also note that .keys is likely returning a list of keys and so it will never be equal to any individual key. You need to check like this: if '1' in TwoGoGo1AllResponses.keys and so on

The code is in the “each frame” section of the code component.

thisGo1Feedback is the image that is supposed to show after their response to the stimulus.

It should go:

fixation cross
stimulus
fixation cross
feedback image
fixation cross

and continue like that…

I changed my code in the each frame section to be:

if '1' in TwoGoGo1AllResponses.keys or '2' in TwoGoGo1AllResponses.keys or '3' in TwoGoGo1AllResponses.keys or '4' in TwoGoGo1AllResponses.keys or '5' in TwoGoGo1AllResponses.keys:
    thisGo1Feedback = 'habitstimuli/penny.png'
else:
    thisGo1Feedback = 'habitstimuli/emptycircle.png'

That seems to work for the first feedback image in the routine. (In a routine I have 3 stimuli and there should be 3 feedback images.) There is some issue with the second and third feedback images not showing…but maybe this is a different issue now?