Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Mouse click accuracy

edited February 2014 in OpenSesame

Hi,

I am trying to make this experiment where in a single trial, 5 letters will be presented in random locations. Participants have to click at all the letters that they saw in a grid shown earlier. I am trying to record the mouse clicks and the letters that appear at the location of the clicks. I have two inline scripts here: SetPos for setting the position and letters to be displayed (this part works fine) and GetClicks gather the mouse click and stores the letter being clicked (in Wordvar variable) (This is the problematic part) . I am using the sketchpad DisplayStim to display the five letters.
image

Here is the full script

http://pastebin.com/xxL4X86x

Right now, the letters get displayed in random locations, but the mouse clicks are not recorded. The screen just freezes at the display.

Any pointers and suggestion will be much appreciated.

Thanks,
Asma

Comments

  • edited 2:57PM

    Hi Asma,

    It's a bit uninituitive, I know, but mouse clicks are reported relative to the top-left, and not relative to the display center. So your error calculation ...

    err = sqrt((xvar-cursor_x)**2+(yvar-cursor_y)**2)
    

    ... goes wrong, because it assumes that cursor_x and cursor_y are relative to display center. What you need to do is compensate for this by adding the display center coordinates (xc and yc in the script below) to the stimulus coordinates (or subtracting them from the cursor coordinates). Like so:

    # Get the coordinates of the display center
    xc = self.get('width')/2
    yc = self.get('height')/2
    # Determine the click error, while taking into account that the mouse
    # clicks are reported relative to top-left, and sketchpad coordinates
    # relative to the display center.
    err = sqrt((xvar+xc-cursor_x)**2+(yvar+yc-cursor_y)**2)
    

    Cheers!
    Sebastiaan

  • edited 2:57PM

    Thanks for the reply Sebastiaan,
    Adding the center coordinates did the trick for collecting mouse response.

    I am still struggling with the accuracy part. Right now, clicks get recorded but the word variable contains the last variable created in SetPos inline script ie 'Word5'

    Here are the two inline scripts:
    For randomizing positions and words: http://pastebin.com/naRujVqz
    For getting mouse click accuracy: http://pastebin.com/t1dQ1wP7

    I am still trying to get a better handle at programming. Any pointers about what is the error in the logic of the program will help greatly.

    Thanks!

  • edited 2:57PM

    I think you are confusing the name of the experimental variable, i.e. Word5 with its value. If you do this ...

    Wordvar = 'Word5'
    exp.set(Wordvar, 'some_word')
    

    You will set the experimental variable Word5 to the value 'some_word'. Note that there are three layers here, which can make things a bit confusing.

    • The Python variable Wordvar, which contains the name of the experimental variable (i.e. Word5).
    • The experimental variable Word5, which contains the value 'some_word'.
    • The value 'some_word'.

    Now let's look at a piece from your script:

    exp.set ('click_%d_word' % n_click, Wordvar)
    

    What you're doing is setting click_1_word (etc.) to Wordvar, which has the value 'Word5'. What you actually want to do is set it to the value of the experimental variable Word5, like so:

    exp.set ('click_%d_word' % n_click, self.get(Wordvar))
    

    Does that clear things up?

  • edited 2:57PM

    Hi Sebastiaan,

    That makes sense but does not work for me. If I use self.get it gives me an error that Wordvar is not set in the script-- which is understandable because I am generating Wordvar in SetPos script and not in GetClick script. Even using exp.get gives me 'a' (the last word (Word5) generated) in all the words clicked (click_%d_word).

    I am not sure how to integrate the information generated in SetPos and GetClick scripts.

    Thanks,
    Asma

  • edited 2:57PM

    Hi Asma,

    Could you paste the exact (line of) script and the error message that is triggered? In general (and in recent versions of OpenSesame), variables that are defined one inline_script also available in other inline_scripts. So the fact you're working across different inline_scripts is in itself not a problem:

    Cheers,
    Sebastiaan

Sign In or Register to comment.