[solved] Touch Screen Corsi Task - Borrowing a little code!!
Hi I have recently begun my PhD and I'm quite new to programming / code etc. I used the below piece of code which I found in another stream as I am developing what I hope will be a touch screen Corsi task. In this participants are required to watch a block sequence and then tap this out on screen in the same order. Sequence lengths vary from 2 to 9. I'm doing it forwards and then backwards, harder than it sounds believe me.
Therefore I need opensesame to regcognise a touch response within the square and not anywhere else on screen and then log the co-ordinate of the touch. To be more specific I need it to do this for each tough, so if the sequence is 5 blocks long, I need SPSS to record 5 taps, whether correct / incorrect and coordinates. I also want reaction time but I'm not sure if this is a later question I might have to post. I used the below code therefore and I think I have it working, of sorts, but I was just wondering if anyone knew, for write up / understanding purposes how exactly the code calculates acceptable distance, how far is too far in essense from the square to be considered correct? I'm sorry if this is completely out of context from the original post as well, I'm relatively new to forums also.
Thank you , Katherine.
from math import sqrt # The maximum error from the target center maxClickErr = 100 # Use Pythagoras to determine the click error and set # the variable `correct` to 1 (correct) or 0 (incorrect) # depending on whether the click error is small enough. # Because the cursor coordinates have 0,0 at the top-left # and the sketchpad coordinates have 0,0 at the center, # we need to compensate for the display size. xc = self.get('width') / 2 yc = self.get('height') / 2 # Determine x and y error dx = self.get('cursor_x')- xc - self.get('xTarget') dy = self.get('cursor_y')- yc - self.get('yTarget') # Determine error clickErr = sqrt(dx**2 + dy**2) # Determine `correct` variable if clickErr <= maxClickErr: exp.set('correct', 1) else: exp.set('correct', 0)