Set specific correct answer based on participant's input in the Experiment info

OS Big Sur 11.2.2:
PsychoPy version 2021.1.2:
What are you trying to achieve?: Set specific correct answer based on participant’s input in the Experiment info

What did you try to make it work?: I created an experiment and, in the .csv file containing the stimuli I created two columns (e.g., corrAnsA and corrAnsB) containing the correct response keys for the two conditions (that the participant has to indicate in the Experiment info).

I need the Builder to read the column corrAnsA in case the participant types “A” as condition and corrAnsB in case it types “B”. I tried setting in the Correct answer field something like:

$corrAns + expInfo[‘Condition’]

or:
$“corrAns” + expInfo[‘Condition’]

but it doesn’t work. Can anyone suggest how to solve it?

Thank you

Daniele

What you’re trying to do is transform a variable name like a string - if corrAns was 1 and expInfo[‘Condition’] was 'A', adding the two together wouldn’t give corrAnsA, it would give 1 + 'A'.

Instead I would add a Variable component called corrAns whose value at the start of the routine is:

{'A': corrAnsA, 'B': corrAnsB}

Then have correct answer be:

$corrAns[expInfo[‘Condition’]]

So, essentially, you’re making a dictionary with the two possible answers in, then indexing that dictionary based on expInfo. If you wanted to cut down on clutter you could even not bother with the Variable and just set correct answer to:

{'A': corrAnsA, 'B': corrAnsB}[expInfo[‘Condition’]]

but I find the long-form way easier to follow. Totally personal preference though!

Thank you!

Daniele