# Updating polygon opacity every trial not working on pavlovia

What I used: Builder with custom code components
Psychopy version: v2020.2.9
operating system: macOS Big Sur version 11.1 Beta

Hi! I have a very simple experiment, where the subject either sees blue and/or orange squares flashing at random locations on the screen, shown at a random interval for 200 ms, and has to report the number of blue and orange squares seen. The number of blue and orange squares are determined randomly, where each color square can appear 0 to 4 times. I do this by setting the opacity of each square to be either 0 or 1 randomly.

Description of the problem: However, when I run this through Pavlovia, the opacities don’t seem to be updated every trial, but only their random locations. I ran a pilot trial and downloaded the data file and it seems that the opacities are updating every trial (as shown below in blue_ans and orange_ans: see code below), but these number of blue/orange squares aren’t reflected in the actual screen online.

I created my shapes through the polygon component in builder:

Below is the custom code component where I define the opacities (e.g. b_1 in the screenshot above) and the random positions. Note: I’ve already defined my randint and shuffle function in JS at the start of my experiment.

``````//begin experiment tab
//initial trial starts at 0
id_trial = 0;
``````
``````//begin routine
// random start of squares
rand_start = randint(0, 4000) / 1000;

// randomize positions of squares
shuffle(x_pos);
shuffle(y_pos);

// random opacity for squares
//had to do randint(0,2) so that it picks a random integer between 0 and 1.
b_1 = randint(0, 2);
b_2 = randint(0, 2);
b_3 = randint(0, 2);
b_4 = randint(0, 2);
o_1 = randint(0, 2);
o_2 = randint(0, 2);
o_3 = randint(0, 2);
o_4 = randint(0, 2);

// store num of b and o squares seen
num_blue = b_1 + b_2 + b_3 + b_4;
num_orange = o_1 + o_2 + o_3 + o_4;

``````
``````//end routine tab
//increment the trial by 1
id_trial = (id_trial + 1);
``````

Any help is greatly appreciated!!

Unfortunatly opacity non changing properly online is a known issue (e.g. see this discussion Change opacity when I click on a rectangle).

I suggest you find another solution, for example changing the color instead of the opacity.

tandy

Thank you for your suggestion. I apologize that I didn’t mention this is a simplified version of a larger experiment. Subjects would see an image at the center (eg. a face) first, and then the squares would randomly appear on top of that face. So changing the colors would necessarily work all the time (if they happen to be on the background, then setting the color to the background color would be fine but if they were on the face it’d be obvious).