Howdy, Stranger!

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

Supported by

Mouse undefined

Hello,

I'm trying to get coordinates of a subject's mouse clicks with inline javascript but I'm getting an error that mouse is undefined.

Previously, I found that coordinates of a subject's mouse clicks were logged as cursor_x and cursor_y, but when I try using these variables in javascript it says these are undefined as well. I think it'll be an easy fix but let me know if anyone's able to help!

Thanks,

Zach

Comments

  • Hi @zach_researcher ,


    Indeed, you can't use the Mouse object in an inline_javascript item like you can in a Python inline_script. But you can use a mouse_response item and then use the resulting cursor_x and cursor_y variables in a subsequent inline_javascript item. Two things come to mind:


    • Are you sure you are in the Run tab of your inline_javascript item? Otherwise the variables won't exist yet...
    • Are you using the vars. notation (instead of the usual var.), like so?


    console.log(vars.cursor_x)
    


    If you upload your experiment here, we can have a closer look, if needed.


    Good luck!


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi @lvanderlinden ,

    I actually sorted it out! I'm not sure if there's a way around this but each time I mentioned the variables I wrote it as vars.cursor_x and vars.cursor_y. I also defined both variables as 0 at the beginning of the experiment

    Thanks,

    Zach

  • Great to hear @zach_researcher !

    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.