How to make stimuli displayable only when the mouse is over them - intertemporal choice task

OS Win10
PsychoPy version : The newest version
Standard Standalone? (y/n) yes
What are you trying to achieve?: make stimuli displayable only when the mouse is over them during an intertemporal choice task.

Dear all,

Please share your wisdom with a novice. :slight_smile:

I want to create an intertemporal choice task, in which the stimuli (reward - delay in days) -that are divided in two parts of the screen- will be displayed only when the mouse is over them and will get hidden again when the mouse goes away. I intend to run this Exp online in pavlovia.

Up to now, I have made the main core of the experiment (by creating text stimuli appearing in specific locations) but I can’t figure out how to do this, and I didn’t find a way online.

Do you have any suggestion, idea ?

Thank you very much in advance :slight_smile:

@PeterIL, if you are using shape stimuli, you could set the opacity of the object depending on whether it contains the mous. In a code component, use in the Each Frame tab (where polygon is your shape component):

polygon.opacity = polygon.contains(mouse)
1 Like

Dear @dvbridges, thank you very much. I use a text stimulus (RA_item).

I tried this code (and also the one you wrote)

if RA_item.contains(mouse):
   RA_item.opacity=1
else: 
   RA_item.opacity =0

In both cases the code works strangely:

The stimulus is shown only if I had my mouse over it when the previous trial ended and NOT online i.e. during the trial
(i.e. if I move the mouse over it nothing happens, but If I had it there before it appears in the next trial). If my mouse wasn’t over the text when the previous trial ended, I get nothing and it doesn’t change during the trial.

Note: I included a mouse (component from the builder) that saves information on every frame. The section in mouse “time relative to” is tricky, I changed it but yet nothing. I don’t know if that could help.

Any suggestion - insight ?

Thank you a lot :slight_smile:

@PeterIL, yes I remember now that the text contains method does not actually work online, its a known issue. A workaround is to place your text, but then overlay a shape that covers the text, and then change the opacity of the shape to reveal or hide the text.

1 Like

God bless you @dvbridges ! I hope I will make it work.

If this work properly in the builder, are you aware whether its use in pavlovia will be okay or it is know to get distorted because it has to become transformed in javascr ?

I have never used pavlovia and wanna ensure that all this work will be translated into pavlovia :slight_smile:

Thanks again for your great help!

@PeterIL, it should all work, and the auto-translate should not have any issues with the code above. If you have any problems getting it to run, create a new post with the errors and we can help to get it running.

1 Like