| Reference | Downloads | Github

Online exp-mouse clicking--"TypeError: mouse is PressedIn is not a function"

  1. Exp background
    #mouse #picture

Participants’ task: use mouse to click 1 out of 4 pictures;
Exp’s task: compare the selected picture with the target in condition file
–correct coded as 1,
–incorrect coded as 0.

  1. Offline PsycoPy–able to run

I wrote the code in the builder’s view, and it succeeded in generating correct response=1, incorrect response=0;

[“correctAcc2” is pre-specified in condition file]

[“clicked” and “score” are newly generated columns according to “thisExp.addData(‘clicked’, imageTestX)”, and “thisExp.addData(‘score’, int(correctAcc2==imageTestX”]

  1. Online Pavlivia–unable to run

After transerring the exp in builder’s view onto Pavlovia, I met the following error:
“TypeError:mouse_record. isPressedIn is not a function”

[mouse_record is the name of that mouse property]

Thank you for reading my question. Appreciate your answer and help.

isPressedIn doesn’t really work in Pavlovia, but there is an alternative approach. Unfortunately I think it requires manually programming the javascript in the code component rather than using auto->JS, so set your code type to “Both”.

The key thing is that instead of using mouse.isPressedIn(object), you need to use object.contains(mouse). See here for an example (the rest of the thread is about a mostly unrelated problem): TypeError: Cannot read property 'addChild' of undefined

Thank you Jonathan.

I have tried both of your suggestions:
a. after setting code type to “Both”, it still shows the same error
[which means it may need manual coding as you suggested]

b. after changing from “if mouse_record.isPressedIn(image_1):” into “if image_1.contains(mouse_record):”, the error disappeared–“TypeError: mouse is PressedIn is not a function”.
[which means “object.contains(mouse)” works. Thank you.]

However, I encountered another error afterwards, which should be attributed to addData code:
exp.addData(‘clicked’, imageTest1)
exp.addData(‘score’, int(correctAcc == imageTest1))

*Both code lines cannot run in Pavlovia
–“thisExp.addData(‘clicked’, imageTest1)”
–“exp.addData(‘clicked’, imageTest1)”

May I ask:
What code should function "exp.addData (’’, ) be converted into in Pavlovia?

Thank you again for your time and answers. :slight_smile:

That one is easy to fix, just replace “exp.addData” with “psychoJS.experiment.addData”, it will add the data to the trial handler for the trial containing that code component.

Thank you very much Jonatha. You solved my problem.