Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Collecting accumulative RT across two sketchpad frames

edited August 2013 in OpenSesame

Can you help? I want to present two frames consecutively for different lengths of time, and allow participants to respond at any time during the two presentations. I guess I need an inline script, but don't know how to write it appropriately... Many thanks, Tilly

Comments

  • edited February 2014

    Hi Tilly,

    The script below shows how you can collect responses while two sketchpads are being presented. In general, the trick is to alternate between showing a display and polling the keyboard. The responses are stored as response1, response_time1, etc. For more details and instructions on how to use this script in your experiment, see the code comments.

    Similar questions have been asked a few times before, and these discussions may be useful as well:

    The script may seem a bit complicated. To get some feel about how this works, I would recommend walking through one of the Python tutorials. You won't need any extreme coding skills, just a basic understanding of the syntax:

    Cheers!
    Sebastiaan

    Update: Fixed typo

    from openexp.keyboard import keyboard
    
    # Durations for the two displays
    duration1 = 1000
    duration2 = 1000
    
    # Displays are copied from sketchpads. To avoid these
    # sketchpads from being shown twice (i.e. once in the 
    # normal way, and once in this inline_script), you can set
    # their 'Run-if' statement to 'never'.
    canvas1 = self.copy_sketchpad('sketchpad1')
    canvas2 = self.copy_sketchpad('sketchpad2')
    
    # Create a keyboard object with a zero timeout to allow
    # for continuous polling.
    my_keyboard = keyboard(exp, timeout=0)
    
    # Keep track of which response we are collecting, in case
    # the participant responds multiple times.
    response_nr = 1
    
    # We collect at most 10 responses, and reset these 10 responses
    # to 'NA' before we start collecting new responses.
    max_response_nr = 10
    for i in range(1, max_response_nr+1):
        exp.set('response%d' % i, 'NA')
        exp.set('response_time%d' % i, 'NA')
    
    # Show the first canvas, and poll the keyboard for the
    # specified duration.
    show_time1 = canvas1.show()
    while self.time() - show_time1 < duration1:
        key, time = my_keyboard.get_key()
        # If a key is pressed, store the key and the response time.
        # The response time is the time after the presentation of the
        # first display.
        if key != None and response_nr <= max_response_nr:      
            exp.set('response%d' % response_nr, key)
            exp.set('response_time%d' % response_nr, time-show_time1)
            response_nr += 1
    
    # Show the second canvas, and poll the keyboard for the
    # specified duration.       
    show_time2 = canvas2.show()
    while self.time() - show_time2 < duration2:
        key, time = my_keyboard.get_key()
        # If a key is pressed, store the key and the response time.
        # The response time is the time after the presentation of the
        # first display.
        if key != None and response_nr <= max_response_nr:      
            exp.set('response%d' % response_nr, key)
            exp.set('response_time%d' % response_nr, time-show_time1)
            response_nr += 1        
    
  • edited 7:58AM

    Hi Sebastiaan,
    Thank you so much for all your help with this - will give it a go!
    BW, Tilly

  • edited 7:58AM

    I think there is a typo in this script. second while loop should compare with "duration2" not "duration1".

Sign In or Register to comment.