[solved] Flicker Paradigm Change Blindness Task
I am currently trying to develop a change blindness task for use in my Master's thesis. I have a good start from reading this post here: http://forum.cogsci.nl/index.php?p=/discussion/663/open-change-blindness-experiment-with-flicker-paradigm/p1
However, it does not follow the quite same procedure that I would like to implement. I am using mouse inputs rather than keyboard responses and would prefer to do the task completely on the computer to avoid interruptions in participant focus. What I would like to do is have OpenSesame record all of an individuals mouse clicks while they are working on the task so that I can have a total for the number of incorrect guesses made by a participant. I am still very new to coding, but was wondering if there was a way to record all of the mouse responses and to only stop the loop of images when they either correctly identify the change on the image or when they run out of time.
I need to be able to specify a spot on the canvas as the "right" answer, but am unsure how to go about this. I thought that maybe using the touch response tool would allow me to specify specific zones on the canvas? I have also read some posts about mouse tracking and using "max click error" to create a radius of pixels, but I believe that the mouse tracking would provide me with much more data than I need. I only want to log their guesses and be able to insert a break command that stops the loop when they obtain the correct answer.
I am using the following script to run my pairs of images in a loop with a gray screen to interrupt and to attempt to record mouse clicks when they occur:
frame_dur = 250
repetitions = 45
start_time = self.time
from openexp.mouse import mouse
from openexp.canvas import canvas
my_mouse = mouse(exp)
my_mouse.set_visible(visible=True)
my_canvas1 = canvas(exp)
my_canvas1.image(exp.get_file(u'Barn1.png'))
my_canvas2 = canvas(exp)
my_canvas2.image(exp.get_file(u'Barn2.png'))
my_canvas_gray = canvas(exp, bgcolor='gray')
for i in range(repetitions):
my_canvas1.show()
resp, position, timestamp = my_mouse.get_click()
if resp != None:
button, position, timestamp = my_mouse.get_click()
my_canvas_gray.show()
resp, position, timestamp = my_mouse.get_click(timeout=80)
my_canvas2.show()
resp, position, timestamp = my_mouse.get_click()
if resp != None:
button, position, timestamp = my_mouse.get_click()
my_canvas_gray.show()
resp, position, timestamp = my_mouse.get_click(timeout=80)
My mouse coding is probably not correct, I am still not clear about how to record the mouse clicks through the inline_script.
Any help would be greatly appreciated.
Thanks,
Ashley E.
Comments
Hi Ashley,
Firstly, yes it is possible to collect all mouse responses and stop when the correct location in your stimulus has been clicked. In your inline_script you could start off by defining that location: e.g.
The
get_click()
command returns a set of coordinates, (in your code that's a variable named 'position'). Here is an example of how you could append responses to a list, and stop when the correct location was clicked:Regardless of how often participants clicked a wrong location, the last response in that list would be the correct one. You could do all kinds of things with that list, e.g. len(response_list) would show you how many clicks a participant needed to get it right.
Hope this helps.
Josh
Josh,
I really appreciate your help! This did help me to make sense of recording the mouse responses. However, I am getting an "invalid syntax" error for the line "while correct_response_given = False"
I inserted your suggestion into my code like this, but is this incorrect?
Thanks,
Ashley
Oops, I made a mistake there; it's
while correct_response_given == False:
, so, with two equals signs instead of one!For all logic statements (such as "if this" or "while that"), 'equals' is denoted with two equals signs. The single
=
is best interpreted as 'becomes'.Cheers,
Josh
Great! This makes a lot more sense.
I ran into one more snag though, I am now getting this error:
"Error while executing inline script
phase: run
item: Practice_pair
line: 32
exception message: 'NoneType' object has no attribute 'getitem'
exception type: TypeError
Traceback:
File "dist\libopensesame\inline_script.py", line 173, in run
File "dist\libopensesame\python_workspace.py", line 111, in _exec
File "", line 33, in
TypeError: 'NoneType' object has no attribute 'getitem' "
Line 32 is this "if (x_min <= position[0] <= x_max) and (y_min <= position[1] <= y_max):"
Is this something to do with position being "none" when a timeout happens? How can I work around this?
Again, I appreciate all of your help!
Hi Ashley,
This can't be due to position being 'none', as line 30 indicates to only run line 32 if position is not 'none'. Are you sure you defined your x_min, x_max, y_min and y_max somewhere?
Cheers
Josh
Josh,
Yes, I believe that I defined the x and y variables correctly. This is the complete code that I have right now:
Is it a problem with the coordinates that I am using?
Thanks,
Ashley
Hi Ashley, did you put the for-loop part in the 'run phase' of your inline_script? (Everything before the for-loop can be kept in the 'prepare phase')
Cheers,
Josh
Josh,
I had everything in the "run" phase. I moved everything before the loop commands to the prepare phase, but I am still getting the same error.
"Error while executing inline script
phase: run
item: Practice_pair
line: 8
exception message: 'NoneType' object has no attribute 'getitem'
exception type: TypeError
Traceback (also in debug window):
File "dist\libopensesame\inline_script.py", line 173, in run
File "dist\libopensesame\python_workspace.py", line 111, in _exec
File "", line 9, in
TypeError: 'NoneType' object has no attribute 'getitem'"
Thanks,
Ashley
Hi,
I didn't read the entire discussion super-thoroughly, but does it solve the issue if you change this line:
if position != 'none':
into that:if position != None:
?If the mouse wasn't clicked
position
should be ofNone
type and not a string.Good luck,
Eduard
Eduard,
Yes, that solved the error. Thank you for your help.
I am starting to understand what they say about writing code; fix one thing and something else breaks.
My cycle is no longer working and I really cannot find a reason why. Before adding Josh's suggestions I had no trouble with the image cycle. When I try to run the experiment now it shows me the first canvas, but will not advance. When I try to click (either in the correct or incorrect zone) the experiment locks up and becomes unresponsive.
Any ideas?
Thanks again for all the help,
Ashley
Hi Ashley,
it locks up, if you click in one of the incorrect areas of the screen, it freezes, because you have no mechanism to avoid an infinite loop. Add a counter to the loop (either based on repetitions or on time), to set a limit to that.
If you click in the correct area, it should work though. Can you verify that the logic of the loop is correct, by adding a print statement after this line:
if (x_min <= position[0] <= x_max)
Something like:
print 'been here'
If the check works fine, it should print this string to the
debug window
. If it doesn't appear, there is probably something wrong with the logic.Good luck,
Eduard
Edit: I just saw the values of
x_max
,x_min
and the y equivalents. Usually, screen coordinates in Opensesame are only positive integers, starting with (0,0) in the topleft corner. Is there a reason why you use negative values there?Eduard,
I thought this section of code set a limit to the repetitions:
When the image is clicked the window becomes unresponsive, and nothing ever prints in the debug window. It does not even respond to the escape key once the images appear. So perhaps I am misunderstanding the loop instructions. It was working fine before I added the response lines of code.
For the x, y I was using the coordinates on the canvas item where it indicates the center is (0,0).
~Ashley
I did some reading on the forum and understand that I misinterpreted the origin for the coordinates. I now have all of my coordinates based on a (0,0) in the top left and thus all of my x y coordinates are positive integers.
However, this did not solve my freezing problem. This is pretty confusing! :-/
Hi,
frame_dur = 250
repetitions = 45
This part doesn't prevent infinite loops that originate in one of the
while
loops, e.g., ifcorrect_response_give
staysFalse
. Do you see that?Another problem that could have caused these issues is the fact that both of your
while
loops contain only computing steps, if a mouse button was clicked. However, since there is no command waiting for the mouse click to occur, which is run on every iteration of thewhile
loop, nothing happens. So, have a look at this:I hope you see the problem. A solution is to move the
else
statement one level up:Let us know if this worked.
Good luck,
Eduard
Okay, definitely getting closer! Thanks so much! With the above changes my experiment now runs, but with a few small hiccups.
This is my current code in the "run" phase:
My only problem now is that the loop will not start until the correct location is clicked, and then after that the loop will not end until after the specified 45 repetitions regardless of where I click. If I begin by clicking on an incorrect location on canvas1 nothing happens, but if I continue to click outside of the correct x,y coordinates the experiment will freeze.
I tried adding a line such as
but this only gives me an error or causes the experiment to freeze.
What I need to happen is for the loop to start automatically and only stop if either the correct response is given or the maximum number of repetitions has occurred.
Thanks again,
Ashley
Well, if you answer the first time correctly,
correct_response_given
is already true, so you won't ever enter the secondwhile
loop. If you don't give the correct response, you're still being caught in the firstwhile
loop. I'm not sure what exactly it is that you want to accomplish (still haven't read your first post, sorry...), but would it work if you wrote the code like this:Does this make sense?
Eduard,
Yes, that makes sense but does not work for what I want to accomplish.
In a change blindness task the objective is to quickly switch back and forth between two images with a gray mask in between. Participants are to identify the change and click on it, which ideally would end the loop and proceed to the next set of images.
There is not a "correct" answer on the first cycle as they haven't been shown the change until canvas2 is presented, and it is very unlikely that anyone would be able to identify the change even in the first 20 cycles. So I want the loop to run until the correct answer is given, and to record any incorrect responses, but not to wait for any mouse input before continuing through the loop.
Is there a way to do this?
Thanks,
Ashley
Oh, of course. Now it makes much more sense to me. Sorry.
What about this code?
The difference here is that I changed the
while
s intoif
s and removed theelse
s, because I don't think they added much to the logic. You just have to make sure, thatmy_mouse.get_click()
is waiting for just as much time as you want to present each of the images' versions.Eduard
Eduard,
Yes, this is perfect! Thank you so much for all your help!
Ashley
Good to hear. We could have saved much time, if I would have been more attentive right from the beginning. Sorry again.
Eduard