| Reference | Downloads | Github

Set fixed amount of time for response using ratingScale

I am currently adapting a script which was used in a behavioural experiment to make it ready for an fMRI study. Accordingly, I need to fix the amount of time the participant has to respond to each question using the ratingScale. Below is the code taken from the behavioural experiment. I would appreciate any suggestions on the easiest way to integrate code for restricting the respone time to 5 seconds regardless of response.

def question_probes (video_name, participant_number, last=0):
“”“Presents question probes, stores responses and presents break screens in between videos and end screen if it is the last trial”""

# use trialhandler to present task, arousal and uncertainty questions from csv file in sequential order. 
fixedQuestions = data.TrialHandler(nReps = 1, method = 'sequential', trialList = data.importConditions('references/fixedQuestions.csv'), name = 'fixedQuestions')

# create rating scale for user to rate thought probes.
ratingScale = visual.RatingScale(win, low=0, high=10, markerStart=5.0,
            leftKeys='1', rightKeys='2', acceptKeys='4', scale = None, labels = None, acceptPreText = 'Press key', tickMarks = [1,10])

# create text stimulus for question probe presentation. 
QuestionText = visual.TextStim(win, color = [-1,-1,-1], alignHoriz = 'center', alignVert= 'top', pos =(0.0, 0.3))
# create text stimuli for low and high scale responses. 
Scale_low = visual.TextStim(win, pos= (-0.5,-0.5), color ='black')
Scale_high = visual.TextStim(win, pos =(0.6, -0.5), color ='black')

# loop through each thought probe in the fixedQuestions created above using trialhandler.
for question in fixedQuestions:
    ratingScale.noResponse = True

    # section for keyboard handling. 
    key = pyglet.window.key
    keyState = key.KeyStateHandler()
    win.winHandle.activate() # to resolve mouse click issue. 
    pos = ratingScale.markerStart
    inc = 0.1 

    # while there is no response from user, present thought probe and scale.
    while ratingScale.noResponse:

        # use 1 and 2 keys to move left and right along scale. 
        if keyState[key._1] is True:
            pos -= inc
        elif keyState[key._2] is True:
            pos += inc
        if pos > 10: 
            pos = 10
        elif pos < 1:
            pos = 1

        # set text of probe and responses 

        # draw text stimuli and rating scale

        # store response using getRating function
        responded = ratingScale.getRating()

    # reset marker to middle of scale each time probe is presented. 

Do you want just the scale to disappear or the whole trial to end?

I would like each question and the scale to be presented for 5 seconds and then move on to the next question and scale. Hopefully that answers your question! Thank you

Yes, It does.

for question in fixedQuestions:
    ratingScale.noResponse = True
    trialClock = core.Clock()
    continueRoutine = True

# all your other stuff...
    while ratingScale.noResponse & continueRoutine:
        t = trialClock.getTime()
        tThisFlip = win.getFutureFlipTime(clock=trialClock)
        tThisFlipGlobal = win.getFutureFlipTime(clock=None)
#other stuff
       if QuestionText.status == STARTED & t> tThisFlipGlobal + 0.5  - 0.001: # frame tolerance
          continueRoutine == False

I am not sure it will work, but I would approach it like this.