OS (Win10): PsychoPy version (3.1.5): Standard Standalone? (y):
What are you trying to achieve?:
I am rather new to psychopy and python in general.
I am trying to adjust the opacity of text stimuli in one routine based on clicked responses that occur in a subsequent routine (in the same loop). I have valid clickable text stimuli, and when one of them is clicked in the second routine, when the loop repeats, I want the clicked stimuli to update the opacity of the corresponding text stimuli in the first routine.
What did you try to make it work?:
I have the opacities of the three text stimuli set to the variables “Step2_Opacity”, “Step3_Opacity”, and “Step4_Opacity”.
In the begin experiment tab, I set each of those variables equal to 0.
In the subsequent routine, in the each frame tab, I have
Step2_Opacity = 1
Step3_Opacity = 1
Step4_Opacity = 1
What specifically went wrong when you tried that?:
The experiment runs fine, but the opacity of the three text stimuli is still stuck at 0. The updated value of 1 is not carrying over when the loop repeats. I also have the click event set to end the routine on a valid click, and when I run through it, it is appropriately ending the routine when I click one of the text stimuli and staying in the routine when I click elsewhere.
This is unnecessary - that code can be deleted. A variable is always equal to itself, and hence this code has no effect. The values of these variables are updated in the second routine, as required.
Do you know this to be the case? Try inserting this temporary debugging code in the “begin routine” tab:
This will tell you if the problem is with the variable changing correctly or not. If the variable is updating, but is having no visible effect, the most likely cause is that you have not set the “opacity” field to update on “every repeat”. If left at the default value of “constant”, the changing variable will have no effect. But you have said that this is set to update.
If the variable is not changing, then you have isolated the problem to the code in the second routine. Again, insert some (temporary) debugging code like this:
Step2_Opacity = 1
etc, to verify that the clicks are being detected.
Thank you for your reply! So I added in those two lines of debugging code and the first time the routine runs, I am getting an opacity of 0 for Step2_Opacity (which is to be expected), and when the second routine in the loop runs, I am getting a print of ‘Step2 clicked’. In the next repeat, I am getting an opacity of 1, but that change is not reflected in the actual opacity of the text stimulus.
Oh wow, you’ve hit upon an old bug/limitation that I’d forgotten about:
i.e. controlling opacity for text stimuli doesn’t work like it does for other stimuli, unless the text content is also being changed at the same time.
A work-around is suggested in the post below, where you can get the same effect indirectly, by having another stimulus (e.g. a filled polygon that matches the background colour of your window) overlap each text stimulus. When you want the text stimulus to be invisible, set the opacity of that polygon to be 1, and set it to 0 when you want the text to be seen:
Although this problem really does need to be fixed in PsychoPy itself, hopefully this will get you up and running.
Good luck. For future reference for others, if this work-around isn’t viable (e.g. because the text stimulus is being drawn on top of a complex image background and can’t simply be masked by a rectangle), then alternatives to make it appear invisible are
to set its position to coordinates that are just outside the visible bounds of window.
to set its text content to be be empty (less preferred, as this can be slow).