[solved] Problems collecting mouse clicks
Hi There,
I am using mnouse clicks in a experiment, it is my first time using this function so I am some kind of lost with it.
I am trying to run a version of the corredor ilussion where subjects must click on one of the discs down that is the closest size to the disc presented up. The image looks a bit like this:
So I put as valid region to click in just the areas inside the radius of the possible answers (to make it easier i just made an squared area) . The in-line code to record the answer looks like this (where the tuples Pos1 - Pos2 and so on are the coordinates of the alternative discs) :
from openexp.sampler import sampler
from openexp.mouse import mouse
my_mouse = mouse(exp, visible=True) #check for visibility
my_mouse.flush()
while True:
button, pos, timestamp = my_mouse.get_click(timeout=0)
if button != None:
pos_x=(pos[0]-1080) #transform to psychopy coordinates
pos_y=-1*(pos[1]-720) #transform to psychopy coordinates
counter_ans=1
if (pos_x>=(pos1[0]-size1/2) and pos_x<=(pos1[0]+size1/2)) and (pos_y>=(pos1[1]-size1/2) and pos_y<=(pos1[1]+size1/2)): #ans1
my_sampler = sampler(exp, exp.get_file(good_ans))
my_sampler.play()
chosen_size=size1
chosen_prop=float(size1/close_ball)
break
elif (pos_x>=(pos2[0]-size2/2) and pos_x<=(pos2[0]+size2/2)) and (pos_y>=(pos2[1]-size2/2) and pos_y<=(pos2[1]+size2/2)) : #ans2
my_sampler = sampler(exp, exp.get_file(good_ans))
my_sampler.play()
chosen_size=float(size2)
chosen_prop=float(size2/close_ball)
break
elif (pos_x>=(pos3[0]-size3/2) and pos_x<=(pos3[0]+size3/2)) and (pos_y>=(pos3[1]-size3/2) and pos_y<=(pos3[1]+size3/2)) : #ans3
my_sampler = sampler(exp, exp.get_file(good_ans))
my_sampler.play()
chosen_size=float(size3)
chosen_prop=float(size3/close_ball)
break
elif (pos_x>=(pos4[0]-size4/2) and pos_x<=(pos4[0]+size4/2)) and (pos_y>=(pos4[1]-size4/2) and pos_y<=(pos4[1]+size4/2)) : #ans4
my_sampler = sampler(exp, exp.get_file(good_ans))
my_sampler.play()
chosen_size=float(size4)
chosen_prop=float(size4/close_ball)
break
elif (pos_x>=(pos5[0]-size5/2) and pos_x<=(pos5[0]+size5/2)) and (pos_y>=(pos5[1]-size5/2) and pos_y<=(pos5[1]+size5/2)) : #ans5
my_sampler = sampler(exp, exp.get_file(good_ans))
my_sampler.play()
chosen_size=float(size5)
chosen_prop=float(size5/close_ball)
break
else:
my_sampler = sampler(exp, exp.get_file(bad_ans))
my_sampler.play()
counter_ans=counter_ans+1
my_mouse.flush()
exp.set("chosen_size", chosen_size)
exp.set("chosen_prop", chosen_prop)
exp.set("x_pos", pos_x)
exp.set("y_pos", pos_y)
exp.set("ans_time", timestamp)
exp.set("repet_answer", counter_ans)
Everythings looks to work fine, except when I go to the log file and I check the mouse position on the screen at the moment of the clicks (pos_x , pos_y) , it records only the position of the last trial and repeated it for all the trials. Something like this:
Any idea where is my mistake? Maybe I am missing something very basic here, but I have performed many potential solutionas and nothing seems to work so far.
Thanks in advance for any ideas.
Cheerrs!
Felipe
Comments
Hi Felipe,
Thanks for the very clear description of your problem! It seems to me you're doing everything in the right way, so the output is quite puzzling... Could it be that the
x_pos
andy_pos
variables are overwritten sometime between the running of your inline_script and the logger?To debug your problem a bit, could you add the following to the very end of your inline_script?
This should give you the x and y coordinates at the time of running. If these differ from the logged coordinates, something must have happened between getting the coordinates and logging them.
Cheers,
Edwin
Hi Edwin,
Thanks a lot for your reply.
I did what you asked me and this is what I get when I put the print lines after the button press in-line code but before the logger Item (so looks fine):
Python: x=-143, y=-496
OpenSesame: x=-143, y=-496
Python: x=-1009, y=-458
OpenSesame: x=-1009, y=-458
Python: x=983, y=-419
OpenSesame: x=983, y=-419
Python: x=990, y=-431
OpenSesame: x=990, y=-431
Nevertheless, the log file looks like this:
So it just repeated the first answer.
Now If i put the print lines after the logger Item the problem apears to be everywhere:
Python: x=-869, y=-424
OpenSesame: x=-869, y=-424
Python: x=-869, y=-424
OpenSesame: x=-869, y=-424
Python: x=-224, y=-402
OpenSesame: x=-224, y=-402
Python: x=-224, y=-402
OpenSesame: x=-869, y=-424
So it seems that the logger item is not renewing the values after every run when it collects the answers.
Any idea what could be? And even better... Any idea how to solve it?
Thanks again for your help.
Cheers!
Felipe
Hi Felipe,
I suspect the problem lies in the structure of your experiment, i.e. that the logger is not called after every click, but is called several times after the last click. So click-click-click-log-log-log, instead of click-log-click-log-click-log, if you see what I mean.
What's the structure of your experiment like? Could you post the script somewhere, or upload a screenshot of the overview area?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan ,
Thanks a lot for your reply! I think your answer is probably close of the root of the problem. Nevertheless is that were the case, shouldn't be that the "Logfile" registers the last answer and not the first one pressed (as is the case in the examples of my previous post)?
Anyway I leave you here the structure and the script of the experiment. I would appreciate a lot if you can take a look on it, because I am still stuck on this issue.
File is here:
https://drive.google.com/file/d/0B6QKZMDpEVQoMlFNcjYzSUdoQU0/view?usp=sharing
Structure looks like this:
(collectanswer is the in-line code i put on the first post of this case)
Thanks in advance,
Felipe
Hi Felipe,
Ok, this was a bizarre one. :-B I'm not exactly sure why, but the issue was due to having 'Transparent variable management' enabled. If you disable this, it works as expected.
(I will probably remove (or at least hide) transparent variable management as a feature, because it's not really optimally designed.)
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thanks a lot for your answer.
But i still dont get it how you manage to make it work without the option of the transparent variable manager. In the experiment I have some pictures that are preload at the beggining of each trial, these are numbers variables in the loop called "picture", then in the prepare phase of the stimulus presentation i call them to load the pics:
banana=('C:\Felipe\experiment{0}.jpg'.format(picture))
then in the run phase I present it:
im=SimpleImageStim(win,banana, flipHoriz=False, pos=(0,0), units='deg')
When i uncheck the box of transparent variable manager, the program crashes because it simply fails to recognize "picture" as a variable.
Any idea how can i bypass this issue in order to run the code without using the transparent variable alternative?
Thanks again in advance.
Felipe
Hi Felipe,
You can access experimental variables with
self.get()
, so you would do something like:Transparent variable management was a way to get around this, but, as I mentioned, it's more trouble than it's worth.
See also:
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thanks a lot Sebastiaan, Everything working fine now.
Cheers!
Felipe