【问题标题】:I want to trigger a response at different points in a loop我想在循环的不同点触发响应
【发布时间】:2016-10-12 06:47:28
【问题描述】:

我在 Psychopy 上创建了一个任务,其中从罐子中取出珠子。抽取 50 个不同的珠子,每个珠子后要求参与者进行概率评分。该任务是从一个 excel 文件循环的,但它需要很长时间才能完成 50 个评级。我希望获得前 10 颗珠子的评分。然后对第二个珠子进行评级,直到抽出 20 个珠子。然后对于接下来的 30 颗珠子,直到第 50 颗珠子,只要求每抽取 5 颗珠子进行一次评级(我对编码真的很陌生,很抱歉这可能提前有多么不正确)。 我已经编写了这样的代码,但不幸的是它不起作用? (在没有评分的回合中,我尝试使用键盘响应来触发序列中的下一个出现)-

for row_index, row in (beads_params_pinkbluegreyratingparamters.xlsx):
if row(0:10) and t >= 0.0 and rating.status == NOT_STARTED:
    break
    rating.tStart = t  # underestimates by a little under one frame
    rating.frameNStart = frameN  # exact frame index
    rating.setAutoDraw(True)
 continueRoutine &= rating.noResponse # a response ends the trial

elif row(12:20:2) and t >= 0.0 and rating.status == NOT_STARTED:
    break
    rating.tStart = t  # underestimates by a little under one frame
    rating.frameNStart = frameN  # exact frame index
    rating.setAutoDraw(True)
continueRoutine &= rating.noResponse

 elif rows.event.getkeys, row(11:19:2):
     elif len(theseKeys) > 0:
        break 
        key_resp_2.keys = theseKeys [-1]
        key_resp_2.rt = key_resp_2.clock.getTime()
     continueRoutine = False
 elif row(20:50:5) and t >= 0.0 and rating.status == NOT_STARTED:
    break
    rating.tStart = t  # underestimates by a little under one frame
    rating.frameNStart = frameN  # exact frame index
    rating.setAutoDraw(True)
continueRoutine &= rating.noResponse
       rows.event.getKeys, row[21, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38 ,39, 41, 42, 43, 44, 46, 47, 48, 49]:
        elif len(theseKeys) > 0:
            key_resp_2.Keys = theseKeys [-1]
            key_resp_2.rt = key_resp_2.clock.getTtime()
         continueRoutine = False

【问题讨论】:

  • 请修正您的代码,有多个拼写错误!

标签: python excel psychopy


【解决方案1】:

您应该只循环一次,但在该循环内执行所有检查:

for row_index, rows in (beads_params_pinkbluegreyratingparamters.xlsx):
    if (row_index < 10):
        rows.ratingscale(0:10)
    elif (row_index >=10 and row_index <20):
        rows.ratingscale(12:20:2)
        rows.key_resp_2(11:19:2)
    elif (row_index >=20):
        rows.ratingscale(25:50:5)
        rows.key_resp_2[21, 22, 23, 24, 26, 27, 28, 29, 31, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49]

请注意,您的代码中存在一些语法错误,例如rows.key_resp_2(11:19:2) 没有意义。

【讨论】:

  • 非常感谢宫城先生的任务回复。
  • 嘿!我试图改进我的语法,但我认为我让它变得更糟了。当我现在运行它时,它说
  • 如果 row(0:10) and t >= 0.0 and rating.status == NOT_STARTED: ^ SyntaxError: invalid syntax
  • @s.libes 您可能需要切片符号,例如rows.ratingscale[0:10]。注意括号的使用。如前所述,您混合了错误的语法,所以我不知道哪些部分完全损坏并且写得不好。
猜你喜欢
  • 2021-11-20
  • 1970-01-01
  • 1970-01-01
  • 2018-08-26
  • 2020-09-25
  • 1970-01-01
  • 2017-01-09
  • 1970-01-01
  • 2014-08-02
相关资源
最近更新 更多