|
Post by alexswainson on Sept 4, 2023 16:20:58 GMT
Hi, I'm new to PsyToolKit and am trying to write a script that records the x and y coordinate of a mouse click. The user is aiming to click the green square, but it doesn't matter where they actually click, I'd just like to save where they clicked in terms of x and y. To start, I've modified an existing piece of code: www.psytoolkit.org/lessons/mouse_tracking.html (Example 2) However, all I'm successfully saving is the x and y coordinates of my square targets. Please could anyone suggest where I'm going wrong? Thanks in advance! My code: options
background color black
fullscreen
# scale
# resolution 1920 1080
mouse on
startbutton text Click here to begin!
fonts
arial 18
table conditions
-100 0
100 0
task track_me
#set &&trackX clear
#set &&trackY clear
#set &&trackT clear
show text "Tap the green square" 0 -250
delay 1000
show rectangle @1 @2 80 80 green
readmouse 1 2000
set &&trackX &&trackX
set &&trackY &&trackY
save TABLEROW @1 @2
save &&trackX
save &&trackY
delay 1000
block test
tasklist
track_me 5
end
|
|
jason
New Member
Posts: 4
|
Post by jason on Sept 5, 2023 16:08:17 GMT
After the readmouse function detects a mouse click, Psytoolkit stores the x/y coordinates in two variables: MOUSE_X and MOUSE_Y (point 5 in the code example you linked). If you change the two lines under "readmouse 1 2000" to "set &&trackX MOUSE_X" and "set &&trackY MOUSE_Y", respectively, the code will likely do what you're hoping it will. I would have guessed this code would crash since &&trackX and &&trackY are never defined.
Note that the variables don't need to be arrays (&&) here as they will just hold one value (the coordinate), so you can change to &trackX and &trackY throughout your code. In the linked example, the code is saving a record of where the mouse was every 20ms of the trial so multiple coordinate values need to be stored.
In the code you've posted, it doesn't look like Psytoolkit is set to wait for a mouse click, but is waiting for the mouse to be over the green square. If you want Psytoolkit to wait for a click, a lowercase l should be added as the first argument: readmouse l 1 2000.
You may also find that putting all the variables in one save line will produce simpler data files (i.e., one line per trial with 5 columns). So, "save TABLEROW @1 @2 &trackX &trackY".
|
|