The error tells you what is going wrong: you are referring to a keyboard object called resp
and then trying to access an attribute of it called .a
. But keyboard objects don’t have an attribute with that name, so an error occurs. Instead, the key that was pressed is stored in an attribute called .keys
(even though it contains just one keypress in this case). So as above, you need to use code like this:
Now I’m not sure what your_keyboard_component_name
should be: in your screenshot shown above, you seem to have two keyboard components, called resp_a
and resp_b
. You can’t have two keyboard objects active at the same time, as they will conflict with each other (unless you have two separate physical keyboards and want to collect input from them independently (and even that works only on Macs and Linux)). So delete one of the keyboard objects, and allow just the remaining one to handle your input. Use the name of that keyboard object to refer to in your code.
Looking though your code snippet above, there seems to be some confusion about how keyboard components work: you don’t need one for each possible key. Instead, you have one keyboard component, and allow it to accept whatever the valid input is. e.g. This could be a sequence of alternatives like:
'a', 'b'
If the components is set to “Force end of routine”, then only a single keypress will be stored (if it is one of the valid options), and it will be kept for you in the .keys
attribute of the keyboard object.
Additionally, look again at the suggested code, which does not match what you typed:
$eval('deck_' + your_keyboard_component_name.keys)
Note that, unlike in the code in your screenshots, we don’t explicitly refer to either a
or b
in that code. The whole point is that we get the letter that was typed by retrieving it from the .keys
attribute of the keyboard. Computers are very literal: you need to type the code exactly as suggested (in this case, the only thing you should change is to provide the correct name for your keyboard component).
You also missed this:
Again, the point here is that we are using code to decide what feedback to provide. Currently you are trying to somehow provide both alternatives at once, via separate text components, which again means the code is fighting against itself. Just provide a single text component, which figures out itself what it needs to display via that single snippet of code.