Solution to achieve the task-switching and reward feedback logic

Description: I am currently working on an experiment using PsychoPy where participants can switch or repeat key presses in a task-switching paradigm. Participants can choose the task for each trial using the ‘left’ or ‘right’ buttons. High reward feedback is given for task switching, while low reward feedback is given for task repetition.

Issue: The primary problem is related to the recognition of key presses in consecutive trials. If a participant repeats a key several times and then changes the key, the feedback does not accurately reflect the change. Instead, the feedback seems to be one trial behind.

I am seeking assistance from the community to understand if there is a more effective way to track key presses across consecutive trials or if there are known issues with the current approach.

Thank you for your help!
Coding:

    key_history = [  ]


keys = event.getKeys()

if 'left' in keys:
    current_key = 'left'
elif 'right' in keys:
    current_key = 'right'
else:
    current_key = None


if current_key is not None and len(key_history) > 0:
    last_key = key_history[-1]
    if current_key == last_key:
        # Repeated key
        msg = '+1 Punkt'
    else:
        # Switched key
        msg = '+3 Punkte'
else:
    # No valid key pressed or first trial, skip feedback
    msg = ''


if current_key is not None:
    key_history.append(current_key)```

Where is this code component in relation to the text component displaying msg?



I have made screenshots for better understanding

Try moving the code component to the top of the routine. The message is being set in the text component before you change its value.

It was successful. I cannot express enough how thankful I am for your response. Thank you so much

1 Like