| Reference | Downloads | Github

How to display a conditional response based on a key press?

Sorry if this question has been asked before but I couldn’t find an answer that related to my project.

I’m creating a task with two images side by side and I want to show a particular value when the image on the right is selected and a different value if the image on the left is selected.

This is sort of an example of what I would want

I know I would have to do some sort of if, then argument. So I’m wondering if anyone can help me with how to translate if press left show associated value from $left and the same for the right.

Insert a code component on the next routine (from the “custom” components panel). Make sure it is above the text component on that routine where you want to give the feedback. In the “begin routine” tab of that code component, insert something like this:

if response.keys == 'left': # or whatever key corresponds to this choice
    feedback = left
    feedback = right

Then in your text component, simply insert $feedback in the “text” file, set to update “every repeat”.

Thank you! This helped!