Hello, I am new to Psychopy and my task is to create an online experiment and show 6 different color of squares at the same time. There will be a fixation cross at the center and squares will surround it. Next, after a break, only one of the squares will change color and participants should click to the square they think changed color. For the test trial I created the same squares I used in initial display trial( same colors from the spreadsheet and same position and to change only one square I thought I can add this at the top of the routine but I get ‘TypeError: Math.random.randint is not a function’ maybe this is not online compatible? what can I do instead?
Copy the colors from the spreadsheet
test_colors = [square_1_color, square_2_color, square_3_color, square_4_color, square_5_color, square_6_color]
Select a random square to change
square_to_change = random.randint(0, 5) # Randomly select one square (0-5)
Replace the chosen square’s color with the new color from the spreadsheet
test_colors[square_to_change] = random_square
Assign the updated colors to the squares
square1.fillColor = test_colors[0]
square2.fillColor = test_colors[1]
square3.fillColor = test_colors[2]
square4.fillColor = test_colors[3]
square5.fillColor = test_colors[4]
square6.fillColor = test_colors[5]
I guess instead of random.randint(0, 5) I should enter randint(0, 5)
thanks a lot!
Wow this is perfect! thank you so much! To make sure, this is how it should look right and only one color of the squares will change or should testsquares be from 1-6 :
hello, the python column is the hues they would see without problem right? - I tried entering the numbers (like this: [-0.467,-0.067,0.333]) and the whole cell (like this: blue = [-0.467,-0.067,0.333]) but I get: * the argument should be an array of numbers of length 3– could you please clarify how to enter the right hues to the spreadsheet?
hello, so if I am understanding correctly I should at first add as a code all the colors I will use like this. Then these will be selected from a spreadsheet from 0-19 let’s say. But there seems to be a problem with how I am entering the colors I guess:
yes that is a way to do it. but I would define the colours in a Begin Experiment tab and not a Begin routine tab. There is a superfluous comma in your last line of code.
hi thank you, could you please clarify where is the superfluous comma in my last line of code because I am seeing the commas are the same in all. Also, this task will be the last task participants will complete, considering that should this still be in the begin experiment? thank you very much!
hi, I have looked at your color sheet and will use the colors there. Now checked the cribsheet and based on that I assume this is how I should be entering the colors? then would it work if I write the name of the colors here in the code to spreadsheet? please let me know if I am missing anything. thank you very much!
As @JensBoelte stated, this code should be in Begin Experiment, not Begin Routine, though it doesn’t matter too much if the routine is only used once.
I don’t think it will work if you put, e.g. blue_bright in your spreadsheet but if you add a line of code in an Auto routine (after this code has run) with something like
colours = [blue_bright, cyan_bright, …] (please type them all out.
Then you could have a column in your spreadsheet called colourIndex (or whatever you like) with a 0 when you want blue_bright
The you can use visualComponentName.setFillColor(colours[colourIndex])
I also added this :visualComponentName.setFillColor(colours[square_1_color,square_2_color,square_3_color,square_4_color,square_5_color,square_6_color]) to the second code component in begin routine but I am getting : visualComponentName is not defined error when I sync it.
Hello, yes I entered as ‘color’ not ‘colour’, I do not think it is the problem:( if we enter the listed colors in psychopy in a spreadsheet it works perfectly, but when I enter them with the numbers like in your sheet or as the latest screenshot I attached, it doesn’t get what colors it should apply to I guess. Could there be another way? I mean, after I show them the squares they will see the same set, only one of them will change colors, so I was thinking a worst case scenario where I would create 50 set squares(total trial number) in properties but then would I be able to add a code that will change only one of the colors in the test trial?