@dvbridges, thank you for your suggestion to look at the PsychoPy version. Indeed, the problem above (file not running) was due to the fact that I was opening the file with PsychoPy2.
I have made some progress in building the box task. In the task I have white “boxes” and each one may “contain” a different color (red or blue).
Right now, upon running the file in attachment, I have four white squares; if I click on one of the squares, the color “below” is revealed.
The problem is that if I click on a second square nothing happens; the change of color works only with the first square I click on - instead this should work for each square till all the colors are potentially “revealed”.
I attached the builder file and the condition file.
In my code I set the following code snippet under “Each Frame”, adapted from this page (I also set “click_on = False” under “Begin Routine”):
if mouse.isPressedIn(p1):
if not click_on:
click_on = True
click_on = t # current time
p1.fillColor = 'red'
else:
click_on = t
if click_on and t - click_on > 10:
click_on = False
p1.fillColor = 'white'
if mouse.isPressedIn(p2):
if not click_on:
click_on = True
click_on = t # current time
p2.fillColor = 'red'
else:
click_on = t
if click_on and t - click_on > 10:
click_on = False
p2.fillColor = 'white'
if mouse.isPressedIn(p3):
if not click_on:
click_on = True
click_on = t # current time
p3.fillColor = 'red'
else:
click_on = t
if click_on and t - click_on > 10:
click_on = False
p3.fillColor = 'white'
if mouse.isPressedIn(p4):
if not click_on:
click_on = True
click_on = t # current time
p4.fillColor = 'blue'
else:
click_on = t
if click_on and t - click_on > 10:
click_on = False
p4.fillColor = 'white'
This code goes with the following simplified condition file:
Again, the problem with this file is that I can unveil only one box, the first one I click on.
I have tried playing with the if statement, for example using ifelse, but the result was the same. I also realize that this code is inelegant and a bit cumbersome especially when I will use, let’s say, 24 boxes (but I am willing to go there if necessary!)
Please let me know how I could modify the code to have the possibility to “unveil” each “box” (the white squares).
conditionsJS.xlsx (8.5 KB)
colRects.psyexp (17.8 KB)
NOTE:
I have tried to use your code to build a loop:
rects = [p1, p2, p3, p4]
for rect in rects:
if mouse.isPressedIn(rect):
if not click_on:
click_on = True
click_on = t # current time
rect.fillColor = 'red'
else:
click_on = t
if click_on and t - click_on > 10:
click_on = False
rect.fillColor = 'white'
This code gives me the same result as before though, and now all the squares are set to be changed to red (while before I had p4 set manually to blue.)
I know that your suggestion was slightly different; but when I try to implement your code in full…
shuffle(myCol)
# Create container of your shapes from Builder
rects = [p1, p2, p3, p4]
# Reset color of shapes
for rect in rects:
rect.setColor('white')
for rect in rects:
if mouse.isPressedIn(rect):
if rect.fillColor == 'white':
rect.setColor(myCol.pop())
…using this conditions file:
I then get the following error: