psychopy.org | Reference | Downloads | Github

Resetting mouse position to center after rating

Hello,

I’m running PsychoPy 1.85.4. on OS High Sierra, using the Builder.

I wonder if there is a possibility to reset the mouse position to center after answering to a rating scale.
Could this be done via a code component?
Or in the customization window of the rating scale component?

Thanks a lot.

Veronika

Try mouse.setPos():
http://www.psychopy.org/api/event.html

1 Like

Hi Michael
I still don’t get where to insert the code.
Tried several options but it always says “mouse is not defined”


Thank you
Veronika

First you need to insert a “mouse” component (above the code component) so that the code has something to refer to. i.e. at the moment, you don’t have anything that exists called “mouse”.

Ah ok. I wasn’t sure if that has to be done in the customs tab of the rating scale.
It worked fine.
Thank you very much for your quick and helpful reply.

Veronika

Hello, I had almost the same problem as Veronica. I did what you wrote but PsychoPy shows error: “if t> = 0.0 and mouse.status == NOT STARTED AttributeError: ‘NoneType’ object no attribute ‘status’”

This what I coded in the builder: personal code window -> each frame -> mouse = mouse.setPos(newPos=(0,0))

What should I change/improve? I am new to PsychoPy and Python language, I will appreciate every bit of advice.

Weronika

Hi Weronika. Please indent your code with four spaces of surround a block of code by ``` before and after to make it more readable.

There are a couple of issues here. One is that you are trying to create a mouse object on every screen refresh. It should just be created once on a given routine, and then you can refer to it as needed. I’m guessing that you already have an object called mouse but then you are effectively re-assigning with this statement, to something that is probably None:

 mouse = mouse.setPos(newPos=(0,0))

Instead, I guess you just want to reset the mouse position once, at the start of the routine. So put the code in that tab of the code component, rather than on the “every refresh” tab. i.e. even if the code worked, you would effectively be keeping the mouse static and preventing it from moving because you would continually be re-zeroing it. So the code would just be this:

mouse.setPos(newPos=(0,0))

i.e. you just need to update an attribute of the mouse, not recreate it (this assumes that you already have a mouse defined).

Hello,

thank you so much for your detailed instruction and help!:slight_smile:

All the best
Weronika