How to customize stimulus color using dialog box input

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): v2021.2.3
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?:
I want to customize the color of some of my stimulus (images).
Let’s say I have 10 images, I want to change the color of image # 1, 3, and 7 only.
The customized color change should be based on dialog box input (if there is a better place to insert this info, I am open).

What did you try to make it work?:
I customized my dialog box to include “color”.
In my conditions file, I created an additional column called “custom_color”.
I have 10 rows, one for each image.
“custom_color” is 1 if I want to change the corresponding image color, and 0 everywhere else.

I tried writing this code (Psychopy tells me it is incorrect syntax):

if custom_color == ‘1’:
colorInput = expInfo[‘color’]
clr = [colorInput ,colorInput ,colorInput ]
else:
clr = [1,1,1]

Finally, for image properties, I have changed “Foreground color” to $clr; set every repeat.

What specifically went wrong when you tried that?:
I am stuck on the syntax, since Psychopy tells me this is incorrectly written.
Where I am stuck:

  1. How to create an “if” conditional statement based on one of the conditional file columns.
  2. How to change image color based on dialogue input (I thought “expInfo” would do the trick, but doesn’t seem to work).

Thank you so much.

Hello ah5005,

expInfo returns a string, not a number.

Best wishes Jens

2 Likes

Therefore

colorInput = float(expInfo[‘color’])

Thank you both! I’ve updated my code. I really appreciate your help.

Last question – my syntax still shows up as incorrect.

I think this is where my issue is:
I am trying to refer to a column in my conditions file.
For trials with a 1, I want to use dialogue box input, otherwise I put a 0 since I want to use my default values.

if color_variable == ‘1’:
colorInput = float(expInfo[‘color’])
clr = [colorInput ,colorInput ,colorInput ]
else:
clr = [1,1,1]

Could you point to the correct way to refer to conditions files variables? I’ve tried $color_variable (with a $sign) but I don’t think that’s it. I’ve tried butting the color_variable on the leftmost, in case it conditions files reads sequentially left to right.

Thank you!

To refer to a spreadsheet variable in code simply use the column name.

1 Like

Thank you so much! The problem has been resolved.
I just had the “wrong” apostrophe, and it was giving me an error.

For anyone else that comes to this page: all number values are integers in the conditions file, Psychopy automatically only looks at one row (or one trial) at a time. But copying and pasting code from this forum somehow gives you the incorrect apostrophe.
And

colorInput = float(expInfo[‘color’])

was the key in fixing my code. Thanks again!