1

我正在设置一个菲茨定律实验,我希望参与者单击开始按钮,沿直线移动鼠标,然后单击目标。单击开始后,如果参与者在垂直方向上向上或向下移动鼠标太多,我想显示一个白屏 30 秒并且不接受任何输入,然后移动到下一个试验。

目前,无论如何,实验的表现就好像我超出了可接受的范围并始终执行 if 语句。

这是我现在拥有的代码:

from psychopy import core

start = mouse.isPressedIn(polygon, buttons=[0])


if start==True:
    thisExp.addData('starttime',core.getTime())
    x, y = mouse.getPos()
    mouse.x.append(x)
    mouse.y.append(y) 
    if y>10 or y<-10:         #this is the statement that isn't resulting in what I would expect
thisExp.addData('penalty',1)

finish = mouse.isPressedIn(polygon2, buttons=[0])

if finish==True:
    thisExp.addData('stoptime',core.getTime())
    continueRoutine=False

我还没有弄清楚嵌套 if 语句下我需要的一切。现在我只是想确保它正常工作。即使查看 csv 文件中收集的 mouse.y 列表数据,它也不会将 if 语句评估为 true,也不会添加惩罚,我可以看到某些情况下 y 超出了我设置的任何范围。

似乎在试验开始后立即收集鼠标位置数据,而不仅仅是在单击多边形之后。但是,开始时间和停止时间似乎确实基于单击多边形和多边形2 的时间。我真的不确定发生了什么。

更新:由于某种原因,直到一天后我才收到有关 Jonas 回复的通知。我希望我有,因为它会让我在几个小时前走上正确的轨道。它是一个构建器代码组件。

我的代码都在运行每一帧。在例程开始时,我添加了:

checkstart = False

使用以下代码,每一帧都解决了这个特定问题:

start = mouse.isPressedIn(polygon, buttons=[0])

if start==True:
    thisExp.addData('starttime',core.getTime())
    x, y = mouse.getPos()
    mouse.x.append(x)
    mouse.y.append(y)
    checkstart=True;

if checkstart==True:
    if y>10 or y <-10:
        thisExp.addData('penalty',1)


finish = mouse.isPressedIn(polygon2, buttons=[0])

if finish==True:
    thisExp.addData('stoptime',core.getTime())
    continueRoutine=False

我仍然不知道为什么在单击多边形之前会收集鼠标位置,但这对我来说并不重要。我可以将鼠标单击的帧的数据与开始按钮对应的位置进行匹配,以获取鼠标路径跟踪的开始。

4

1 回答 1

0

我的代码都在运行每一帧。在例程开始时,我添加了:

checkstart = False

使用以下代码,每一帧都解决了这个特定问题:

start = mouse.isPressedIn(polygon, buttons=[0])

if start==True:
    thisExp.addData('starttime',core.getTime())
    x, y = mouse.getPos()
    mouse.x.append(x)
    mouse.y.append(y)
    checkstart=True;

if checkstart==True:
    if y>10 or y <-10:
        thisExp.addData('penalty',1)


finish = mouse.isPressedIn(polygon2, buttons=[0])

if finish==True:
    thisExp.addData('stoptime',core.getTime())
    continueRoutine=False

我仍然不知道为什么在单击多边形之前会收集鼠标位置,但这对我来说并不重要。我可以将鼠标单击的帧的数据与开始按钮对应的位置进行匹配,以获取鼠标路径跟踪的开始。

于 2014-11-08T01:40:50.723 回答