Change text component color based on image file path

Hi all,

Currently designing an experiment in v2021.2.3.
I am trying to use a code component to change the color of two text elements depending on the stimulus image that is shown.
To be specific, I want the text elements to be white only if the image ‘stims/crosshair.png’ is on the screen, and to otherwise be gray to blend into the background.

$cc_stimulus is a column from an excel input spreadsheet that either points to different pleasant image filepaths OR ‘stims/crosshair.png’. This is the variable that I input to the “Image” section of my builder Image component:

My code so far for the conditional color change of the text components is as follows:


Where $cc_yescol and $cc_nocol are the variables that I put as the color of the text components.

There is no error message when I try to run the code–the text components just are not turning white when I want them to, when ‘stims/crosshair.png’ is on the screen. Is it a problem with my code in the Each Frame tab?

Thank you in advance for your help!

setImage is the function to set the image, it shouldn’t be used in comparisons like this. You need to do if cc_stimulus == 'stims/crosshair.png': instead

1 Like

Wow. I can’t believe that was it. I was certain that I had tried that. Thank you for your help!