How to refer value from Excel into text output in a code builder


I’m currently developing an experiment where subjects have to press keys to respond to some questions.

Based on their responses , I need to provide some information in a text output, based on some conditions which will consist of:

Some text + reference to a value from the Excel file belonging to the trialLoop

More precisely, I want to add “$excelVariable1”

Here, “choice” is randomly defined before as either left or right by me in a previous component.
The user presses the left or right arrow key , which fills in keyDecisionResponse.keys

The Excel file looks like the below example:

Therefore, for each trial:

IF the user presses LEFT and the computer randomly assigns choice=LEFT, then I would like to see on the screen the following message :

“Result 1 is 75”

…and so on

If left+right on trial 2, then (second iteration of loop, third branch from the IF clause):

“Result 3 is 38”

The users press on left or right in previous routines on keyboard components. The choice is assigned randomly in a previous routine.

How can I achieve this? It tried various ways and looked for some answers, but could not find.

Thanks in advance!

Don’t use the $ in a code component.

The $ means “treat the following as code”.

Thanks, @wakecarter.

How do I refer to that value from the Excel file?
How can I “access” rows of values corresponding to columns in Excel: excelVariable1, excelVariable2, excelVariable3 or excelVariable4 ?

Row 25 is nearly correct .

Remove the dollar sign.

Add str() around the column name because you need text not a number.

Your other similar rows are missing the plus sign.

Thank you, @wakecarter, this was indeed the solution.