Allowing a user to change their answer (keyboard response)

Link to Experiment Online: https://pavlovia.org/CAMaitland/socialmotivationandidentity

I recently updated Psychopy and some old Py code that previously worked no longer does due to the changes in keyboard functions.

In my experiment, participants need to push the left OR right key multiple times in order to make a choice and progress to the next routine. The code below should mean that if a participant pushes the left then right key (i.e. a mistake) the keyboard will reset itself, such that it deletes the keys already pushed and is ready for new key input. Here is the code that previously worked:

if key_resp_14.keys == ['left', 'right']:
    event.clearEvents(eventType='keyboard')
    key_resp_14 = event.BuilderKeyResponse()
    theseKeys = event.getKeys(keyList=['left', 'right'])

I think it’s related to changes in clearEvents, but I’m unsure. Anybody have any ideas of how to code this using the updated functions?

I don’t know what recent chagnes would have caused that (although it may depend how long ago this was working for you). The place where things have changed is that there’s now a Keyboard class that will give better performance:
https://www.psychopy.org/api/hardware/keyboard.html

Generally, the solution to what you’re asking is to set the Keyboard component not to force the end of the Routine (so that multiple keys can be pressed) and then to store the final key. i.e. it shouldn’t need any code at all.