30  Using input files

Information in an input file can have different purposes. For example, you can use this information to:

Let’s look at these use cases in turn.

30.1 Changing component properties

30.1.1 The basic idea

How do you tell PsychoPy that you want to change a component property (e.g., a piece of text, an image or a stimulus location) from one trial to the next? You tell PsychoPy that the property is variable.

How do you tell PsychoPy that the component property is variable? You provide PsychoPy with a variable name and set the component property to “set every repeat”.

Frequently, the variable name will come from the header row in your input file.1 It is probably most instructive to have a look at a more detailed example of this idea. We will use the Text property of the Text component for explaining the basic idea in more detail. Other properties will then be dealt with more briefly.

30.1.2 Changing text

If your aim is to change a piece of text from one trial to the next, you must update the Text property of the Text component. For this to work, you need:

  • A variable name in the Text property field that is preceded by a $ sign.2
  • An input file that has a column header that matches this variable name exactly.
  • To select “set every repeat”.

These requirements are illustrated here:

Using information from an input file in a Text component by linking a column in the input file to the Text property and setting the repeat type to 'set every repeat'.

Tip

As this is such a common mistake, let us reiterate that the variable name in the Text field and the header in the input file need to match exactly. For example, the experiment will not run if you have stim in the Text field and Stim in the input file!

A frequent error that can be hard to spot is a space after the column header in Excel, e.g., stim . The most straightforward way to identify this issue is to open the input file in Excel and to right-align the contents of the columns.

Note that sometimes you might need more than one column in the input file to update stimulus properties. For example, to udpate the Stroop stimulus RED, you need to get information about the word as well as the colour from the input file. Thus, your input file needs separate columns for defining word and colour (see my Stroop experiment in Chapter 28). The same is true when you would like to change, say, the stimulus and its location from trial to trial.

30.1.3 Changing images

If your experiment uses images that change from trial to trial, you will need to use an Image component and tell PsychoPy that the image should be updated on every repeat. The basic idea is the same as before: You provide PsychoPy with a variable name preceded by a $ sign and select “set every repeat”:

Using a variable to define the Image property of an Image component.

Again, the variable name needs to match a column header in the input file:

Screenshot of the input file showing the `img` column.

Note that the file name needs to include the extension of the file (.png in this example). Also, when defined without a path, the images must be located in the same folder as the .psyexp file.

30.1.4 Changing locations

If your experiment requires the location of stimuli to change from trial to trial, you will need to use the Position property of your component. The basic idea is the same as before: You provide PsychoPy with a variable name and select “set every repeat”. For example, if you would like to change the stimulus position along the y-axis, you could achieve this in the following way:

Screenshot showing the Position property set to (0, ypos) and 'set every repeat'.

Again, the variable name needs to match a column header in the input file:

Screenshot of an input file showing the yPos column.

You might have noticed a difference to before though: We did not include the $ sign. Why is this? Note that next to “Position [x,y]” there already is a $ sign. This indicates that you should not add a $ sign here.3

What is the logic behind this? You do not need to add the $ sign when it does not make sense to enter text into a given field. For example, the position along one of the axes can only be a number. If you enter text, it is clear that this is meant to be a variable name. On the other hand, other properties can be represented by text (e.g., colours or file names). In these cases, you need to add the $ sign to indicate that you would like PsychoPy to interpret the input as a variable name.

30.1.5 Changing other properties

All other properties that can be changed from trial to trial (e.g., size, colour or orientation) work analogously to the examples illustrated above.

30.2 Determining a correct response

Information in the input file can also be used to determine if the participant gave a correct response. Here is the Keyboard component from our flanker task:

Screenshot showing a screenshot of the input file and the response properties of a Keyboard component, with an arrow pointing from the corrAns column of the input file to the 'Correct answer' property of the Keyboard component.

The orange arrow illustrates how the column called corrAns in our input file is linked with our Keyboard component. Note that you need to tick “Store correct” for the field “Correct answer” to appear. Also note that the “Allowed keys” can be constant as these are the same on every trial.

If “Store correct” is ticked and a variable name for “Correct answer” is provided, PsychoPy will automatically write information about the accuracy of responses to the output file it produces. However, this information is not just useful for the output file. It can also be used to give participants online feedback about their performance. This is something we will have a closer look at next week.

30.3 Adding further information to the output file

What happens to information in the input file that is not used in one of the components? For example, the information about the congruency in our flanker task? Like the other information in the input file, it will automatically be written to the output file that PsychoPy creates. When you analyse your data, it will be helpful to have this information readily available.


  1. When you learn how to give feedback, you will see that you can also use Python code to create variable names.↩︎

  2. Why is there a $ sign before the variable name? This tells PsychoPy that you don’t mean to literally present stim on the screen, but that stim should be interpreted as a variable name.↩︎

  3. In fact, doing so would stop the experiment from running.↩︎