| Reference | Downloads | Github

Provide feedback by highlighting answer

If this template helps then use it. If not then just delete and start from scratch.

OS (Mac OS Sierra):
PsychoPy version (e.g. 1.84.x):
**Standard Standalone? (y)
What are you trying to achieve?:

The experiment I’m trying to build involves showing 2 stimuli to the participant. This stimuli can appear can appear at 4 positions of the screen (i.e. top, bottom, left, right). The name of the keyboard component is “response” and the allowed keypress is the up, down, left, right arrows. I have already done this bit and it is running fine.

The one that I want to do next is when the participant chooses the correct answer, I want a “green border” surrounding the correct choice and a “red border” for the incorrect choice as feedback.

What did you try to make it work?:

I placed an image of a green box and red box at the 4 possible positions and set the opacity to 0. I then wrote this into the code component in the “each frame” tab

if response.corr:

What specifically went wrong when you tried that?:

When I tried running the experiment, regardless of whether the answer is correct or not, none of the borders appeared.

Any help is appreciated.

Many thanks,

Have you set the opacity of those stimuli to be “constant”? If set to update “every frame”, that will conflict with your custom code.

Also, how does the routine end? Is there time for the change to be visible?

Hi Michael, yes the opacity is set to constant.

Currently, there isn’t because I wanted to test if the borders would show up. Ideally, I would like the change to be visible for 2 seconds. I have not figured out how to do yet. If you have any suggestions on how to achieve that, I would truly appreciate it :slight_smile:

OK, the easiest approach to this is to split your trial across two routines, one containing the text stimuli and the keyboard response, and the other with the text stimuli and the borders. The first routine is set to end when a key is pressed, the second has a fixed duration of 2 seconds.

In Builder, you can copy an entire routine. Do that, so the text stimuli are identical and will display seamlessly so the subject won’t notice the transition.

In the first routine, delete all of the border stimuli and the code component, and set the key press to force the end of the routine. All stimuli and the keyboard have no set duration.

In the second routine, delete four of the border stimuli and the keyboard component. Give all of the stimuli fixed durations of 2 s. Give all of the four border stimuli an opacity of 1.0.

In the code component, put something like this in the “begin routine” tab:

if response.corr:
    border_colour = 'green'
    border_colour = 'red'

And put border_colour in the colour field of your four border stimuli, set to update on every routine. Make sure the code component is above all of the border stimuli, so they get access to the latest value before they are displayed.

I’ve followed your instructions.

here is the new flow

I ran the experiment and got this error message

if response.corr:
NameError: name ‘response’ is not defined

Also, now that I only have four borders, I’m not sure what to put as image name. For now, I’ve put ‘green.png’. I’m not sure if this is correct.

OK, sorry I just assumed you were using polygon stimuli for your borders rather than displaying image files from disk. Thus I assumed that you had four different rectangles labelled top, bottom, left and right, rather than four sides.

The polygon stimulus (i.e. set to be a rectangle) would be the way to go. That way, you would only need two stimuli (one rectangle for each of your options). Defining a polygon is also much more flexible than using image files: you can easily move and re-size them and change their colours, without having to edit an image file.

i.e. your second routine would have a code component, your two image stimuli, and two polygon stimuli.

This could happen if the code is in the wrong tab. e.g. if it is in the “begin experiment” tab, the keyboard component has not been created at that point. The code would need to be in the “begin routine” tab.

Thank you Michael! Everything works perfectly now :slight_smile:

1 Like