Change opacity when I click on a rectangle

URL of experiment: https://pavlovia.org/Mark/sym1-0

Description of the problem:
Hi! My aim is that when a participant clicks with the mouse on a rectangle, the opacity of the rectangle should change from 0.1 to 1.0. This works fine under normal conditions but not online. Here, the opacity is not changed after clicking on the rectangle.

In a code component I have the following code (recallR1 refers to the name of the first rectangle):

Begin routine:
Python:
recallR1.opacity = 0.1

JS:
recallR1.opacity = 0.1;

Each frame:
Python:
if mouse.isPressedIn(recallR1):
recallR1.opacity = 1
JS:
if (mouse.isPressedIn(recallR1)) {
recallR1.opacity = 1;
}

Many thanks for any help!

Hi,

I also had problems with opacity niìot changing online a while back, but I resolved the issue changing the color of the polygon (since mine was supposed to disappear entirely).

Insted of using recallR1.opacity try naming the opacity inside the builder something like $myOpacity and then change myOpacity in the code component.

Also try changing the opacity setting to change from constant to update every frame if the previous suggestion does not work.

Also just to be sure place the code component at the be very top of the component list!

tandy

2 Likes

Hi tandy,

Thank you so much for your answer!
It did not work with the opacity but based on your advices I changed the color. Now it works online, at least with a black/white design :smile:

1 Like

Yeah I don’t know why opacity doesn’t want to cooperate online! :sweat_smile:

1 Like

Try object.setOpacity(1) with the opacity in the object component set to constant.

However, I have a feeling that there is an opacity related bug in some versions.

There seems to be a big issue with modifying the opacity of visual stimuli in online experiments. It is a known issue since version 2020.2 was released and has not been fixed yet.

1 Like

Hi, I think I stumbled on the same issue. I noticed all of my older scripts aren´t working any more when recompiled, and I think the reason is I was using opacity to show either one stimulus (polygon) or another in a given trial. Since I updated to the new Psychopy version (2020.2.8) it appears that the opacity values are not updated systematically, so some of the stimuli keep the value from the previous trial. What´s a bit bizarre to me, is that this seems to happen completely randomly.

Does anybody know what the latest version was, that one could re-install to avoid the bug?

Thanks!

Matteo

Quick question about naming the opacity inside the builder. Could you elaborate more on that? I am having a similar issue and I can’t seem to figure it out. Thanks!

Hi,

I’ll try to rephrase my point. Beware that it has been a while since I last dabbled in Psychopy!

Basically when creating the experiment in builder view you can assing a variable to a component feature. For example the text inside a text component could be “Hello World!” or $myText defined elsewhere in a code component as myText = “Hello World!” and the end resoult would be tha same.

Using the same principle you can change the opacity of a componet like a polygon or an image by writing a variable (e.g. $myOpacity) insted of a value in the component proprerties and then set the value of myOpacity in a code component.

I hope this helped,
tandy