I created a custom code component in the psychopy builder to shuffle the colours of the objects displayed in my experiment. After the objects are coloured, I need to calculate the average size of the objects of each colour. The issue I’m having is that I need to create a loop that shuffles the colours and calculates the averages again if the two averages are the same. I’ve tried using a do/while loop in the JS part of the code component, but I can’t get it to work on Pavlovia. Below is the code I have tried.
I took a look at the console because, I keep getting an error that “c1_color” is not defined. I have a list called “colors” initialized at the start of the experiment, and each item is a string of a color name. The console is showing that c1_color = colors[0], so it seems like calling an index in the loop doesn’t seem to work. I’m not entirely sure how to fix this though.
I currently I have a list of color names, and each color name is as a string item in the list. Then the color of each circle is defined as an index in the list. For example, I have it coded like this:
Using the color name has been working for me in JS! And when I try out the RBG values, the experiment gets stuck at the “initializing this experiment” screen.
I went through the tutorial, and it looks like a syntax error! It looks like because it’s stuck at initializing, it doesn’t show the source code. So, I went through my code components, but I just can’t find the extra “;”.
Thanks, Thomas! That worked and now I have the syntax error solved. I’m still running into the the initial error, where c1_color is not defined. I updated the list of colors so that it uses RBG codes, but that still doesn’t seem to work.
Ah – I think the issue is that c1_color = colors[0] was inside a do clause and therefore variables set within it haven’t been initialised. Add c1_color = ‘’ etc. in Begin Experiment should also work.