Can't implement a conditions file including a variable

OS: Win10
PsychoPy version: 2020-2-6
What are you trying to achieve?:
I want to present one of different image stimuli each time the routine is repeated. Depending on what the exact stimulus is, the position should vary. For this purpose I have a .csv file which assigns the position (stim1_pos) to the stimulus (stim1). But the position is depending on the screen size. So, I’ve implemented the credit card method and it works fine for the size of the stimulus (stim1 → (3.1 * x_scale, 3.1 * y_scale)). However, now I wanr the position to be read from the conditions file via $stim1_pos. The corresponding column is indicated for instance with: [0,0] (which works fine) or [0, -0.04 * y_scale] (which doesn’t work).

What specifically went wrong when you tried that?:
The routine won’t start because y_scale is not defined when the conditions file is called for the position. However, y_scale is defined when in the exact same stim1 Properties the size is specified with (3.1 * x_scale, 3.1 * y_scale).
I have included the error message. Hope that helps…

“C:\Users…”, line 1072, in
trialList=data.importConditions(‘conditions\practice.xlsx’),
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 338, in importConditions
trialList, fieldNames = _attemptImport(fileName=fileName)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 256, in _attemptImport
trialList, fieldNames = pandasToDictList(trialsArr)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\data\utils.py”, line 313, in pandasToDictList
val = eval(val)
File “”, line 1, in
NameError: name ‘y_scale’ is not defined

Have you written y_scale in your conditions file?

I would recommend putting the x and y coordinates in cm as separate columns in your spreadsheet, and then add y_scale in the component, e.g. [xPos, y_scale * yPos]

I assume that the position is set to change every repeat instead of constant.

Thank you very much for your fast response.
You are right, I have written y_scale in the conditions file (which didn’t work). And the position is set to change every repeat.

Your solution seems to work the way I want it. Thanks!
I think I got confused because I thought I always have to call the columns of my spreadsheet with a $-sign in front, like…
Image: $stim1
Position [x,y]: $stim1_pos
and so on. Then I tried something similar to your suggestion but with multiple $-signs (like [$xPos, $yPos*y_scale]). That didn’t work because of syntax error.

But now it works. Thanks!

The dollar sign doesn’t mean “this is a variable”. It means “interpret this text as code”.

In the PsychoPy components, some fields have a hard coded $ to the left of the field. In this case a dollar is not required because anything you write will be interpreted as code.

In the past there was at least one field which didn’t follow this rule so it’s worth trying with and without the dollar, but when you do use one put it at the start of the field.

1 Like

Thank you very much for the additional information! =)