Howdy, Stranger!

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

Supported by

[open] Help needed using a sequence to 'pause' an experiment.

edited January 2013 in OpenSesame

Hi. Sorry if this has been covered here before, but I went through the forum and couldn’t find anything. I’m totally new to OpenSesame so am probably missing something simple, but any help would be appreciated. :) I’m running 0.27 through Parallels.

Basically, I’m building two experiments.

In Experiment 1, participants are given a vigilance task. They’re presented with a set of patterned slides, and respond with a mouseclick when they see a slide containing vertical line patterns. At the same time, they hear 42 pieces of music interspersed with 42 periods of silence.

My overview looks like this:

image

However, participants should be able 'pause' the experiment at any time by pressing the space key. When they do, the MemoryQuestionnaire sequence should be shown, and, when that is completed, the visual/auditory stimuli sequence should resume from where it left off. Participants should be able to do this as many times as they want.

The problem I’m having is finding a way to implement this. Do you have any suggestions on where within the overview I should be placing the MemoryQuestionnaire sequence?

Additionally, is there any way to record whether the participants are correctly identifying the target slides? It seems that wherever I put a mouse_response item, the task sequence is interrupted. This isn’t essential, but would be useful.

For Experiment 2, participants are presented with a piece of music, and asked whether they associate it with a particular memory. If they respond positively, they are shown the MemoryQuestionnaire sequence. At present the overview looks like this:

image

I believe this will work correctly, I’m just wondering which ‘run if’ command I should use for the MemoryQuestionnaire sequence. I’d only like the questionnaire sequence to start if the participant selects the relevant button widget on the MemoryConfirmation form_base.

Thanks in advance!

Comments

  • edited 5:29AM

    ITA

    Hi,

    We will get back to you as soon as possible!

    Best,

    Lotje

  • edited January 2014

    Hi,

    With regard to your first question, I have assumed that your experiment should look as follows:

    1. Participants are presented with a stream of slides. They perform a go-nogo task for which they have to make a mouse click if the slide is oriented vertically, and to retract from responding otherwise.
    2. On half of the trials, a sound file is played simultaneously with the presentation of the stream of slide.
    3. During stimulus presentation, participants can pause the stream by pressing the space bar. If they do so, a form item will be run, and the sound stimulus is paused. After giving a response to the form item, the stream of slide and the sound stimulus continue.
    4. The mouse click responses (and the response on the eventual form item) should be logged after every slide presentation.

    I would advise you to use a bit of Python inline coding to achieve this. I think in the end this will be easier than using the parallel plugin. Basically, what we want to do is polling the keyboard and the mouse simultaneously after every slide presentation.

    The following script should give you an example of how to do this (see comments for a more detailed explanation):

    import pygame
    from openexp.exceptions import response_error
    
    # Start by playing the sound file:
    my_sampler.play()
    sampler_paused = False
    
    # Walk through the list of patches:
    for i in range(len(patch_list)):
    
        # If the sampler was paused in the previous iteration, it has
        # to be resumed.
        if sampler_paused:
            my_sampler.resume()
    
        # Determine the stimulus by selecting one item from the
        # stimulus list (without replacement). 
        # (Of course, you might do this differently, for example 
        # by defining the variable 'stim' in a loop item.)
        stim = patch_list.pop()
    
        # Determine the absolute path to the image in the file pool:
        path = exp.get_file(stim)
    
        # Set the stimulus for future use in the GUI (notably, the logger
        # item):
        exp.set("stim", stim)
    
    
        # Show the stimulus:
    
        # Start with a gray background for a certain duration:
        my_canvas.clear()
    
        # We have to draw something in order to clear the background.
        my_canvas.circle(0,0,0,color=self.get('background'))
        my_canvas.show()
        self.sleep(wait)
    
        # Present the patch
        my_canvas.image(path)
        my_canvas.show()
    
        # The patch is presented until a mouse or key response is given,
        # or a timeout (of duration ISI) occurred:
    
        # Geth the current time:
        start_time = self.time()
    
        # Give the value 'time_passed' a beginning value (0).
        time_passed = 0
    
        # Check for key or mouse responses until a timeout occurs:
        while time_passed < ISI:
    
            # Keep checking whether the duration  of this
            # while loop is still below the maximum duration
            # (i.e. ISI).
            time_passed = self.time()-start_time
    
            # To poll the keyboard and mouse at the same time, we use pygame
            # directly. This means that this piece of code requires the xpyriment
            # or pygame backend! See:
            # <http://www.pygame.org/docs/ref/event.html>
    
            # First, give the variables 'button' and 'key' the beginning
            # value 'False':
            button = False
            key = False
    
            # Loop through all 'events', which are key presses or button clicks
            for event in pygame.event.get([pygame.MOUSEBUTTONDOWN, pygame.KEYDOWN]):
                if event.type == pygame.MOUSEBUTTONDOWN:
                    button = True
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        raise response_error("The escape key was pressed.")
    
                    # Make sure the stream is only paused by a press on the 
                    # space bar (and not by any key press):
                    elif event.key == pygame.K_SPACE:
                        key = True
    
            # If a key was pressed or a button was clicked, exit the loop
            if button or key:
                break
    
        # Set the given responses so that they will be logged by
        # the logger item. Note that for the variable "mouse_click" (see below)
        # True' indicates that a mouse click was given, whereas'False'
        # indicates that no mouse response was given. This, in combination
        # with the variable 'stim', will enable you to evaluate participants'
        # performance (i.e. whether a mouse click was correct or a false alarm, etc.):
        exp.set("mouse_click", button)
    
        # If a mouse response was collected, the for loop will be
        # continued. However, if the spacebar was pressed, we need to
        # do something else:
        if key:
    
            # Pause the sampler:
            my_sampler.pause()
            # And set 'sampler_paused' to True, such that we won't
            # forget to resumse the sound stimulus after the pause.
            sampler_paused = True
    
            # Show the in-the-GUI-prepared form items:
            # NOTE: the 'Run if' box for this form item should
            # be set to 'never' in the GUI.
            self.experiment.items['mc'].prepare()
            self.experiment.items['mc'].run()
    
        # Finally, log the responses:
        # NOTE: the 'Run if' box for this logger item should
        # be set to 'never' in the GUI.
        self.experiment.items['logger'].prepare()
        self.experiment.items['logger'].run()
    
        # And set the variable 'form_response' to 'NA' again.
        exp.set('form_response', "NA")
    

    Note that the above code should be put in the "Run phase" tab of an inline_script item that is appended to your VisualStimuliSequence item. It is assumed that 'my_canvas' and 'my_sampler' are already defined in the "Prepare phase" tab of the same inline_script item. For more information on how to do this, see:

    The overview of the example experiment looks like this:

    image

    and the full experiment can be downloaded here (simply save with the extension 'opensesame.tar.gz'). It is assumed that two .wav files called "sound1.wav" and "sound2.wav" are placed in the file pool, so the experiment will only run when you do so.

    I hope this will get you started. If you still encounter any problems getting your first experiment to work, please let us know!

    With regard to your second question, what you should put in the 'Run if' box(es) in your TaskSequence depends on the value you gave to the variable 'var' in your button widgets. If you defined a given widget button like so:

    widget 1 2 1 1 button var="button1" text="I agree"

    the variable 'button1' is declared and will have the value 'no' if the button was not pressed, and the value 'yes' if the button was pressed.

    Therefore, if you want to run another item only if button1 was pressed, you could use the square-bracket method and set the "Run if" statement of this item to:

    [button1] = yes

    For more information about variables and condition statements, see also:

    Hope this helps and don't hesitate to ask any further questions!

    Best,

    Lotje

  • edited 5:29AM

    Hi Lotje, thanks very much for your help! The second experiment is now running perfectly, and thanks to your template, the first is almost there.

    The only problem I’m having is getting the sampler to play all of the sound_list files alongside the patch_list files. At the moment, in the template, the sound1.wav file is played at the beginning of the experiment, but the sampler doesn’t move on to sound2.wav. I was wondering if there’s anything I can put into the code to ensure that the sampler plays all of the musical stimuli?

    Thanks again.

  • edited 5:29AM

    Apologies for the shameless bump, but is there anyone who might be able to point me in the right direction here, I'm at a total loss for what to do next. Any tips greatly appreciated :)

  • edited 5:29AM

    Hi,

    Sorry for the delay.

    I think the problem is that your currently running only one trial. And because only one sampler item is run per trial, this leads to only one sound file being played.

    Perhaps the following changes could solve this:

    • Set the number of cycles in the experimental loop to the number of sound files
    • Because multiple trials will be run, we need to define a patch_list for every trial separately (rather than only once at the beginning of the experiment)

    To achieve the latter, remove the part of the first inline_script item (called 'constants', in the example) where we declared the patch_list. So this first inline_script item now looks something like this:

    # Here we'll declare the global variables of the
    # experiment:
    
    # Import the module 'random', which we'll need to shuffle the 
    # patch list:
    global random
    import random
    
    # Declare the sound list:
    global sound_list
    sound_list = ["sound1.wav", "sound2.wav"]
    random.shuffle(sound_list)
    
    # Declare durations in ms:
    global wait, ISI
    # Wait between blank screen and patch (to make it 
    # flickering):
    wait = 100
    # Inter stimulus interval:
    ISI = 1000
    

    (By the way, I noticed that in the old script I accidentally shuffled 'patch_list' twice, and did not shuffle 'sound_list', so we should change this too, see line 12 of the above script).

    Next, append a new inline_script item to the beginning of the sequence called 'vigilance_task'. Here, we will define the patch_list (because this list should be renewed for every trial):

    # Declare the visual stimulus list:
    global patch_list
    patch_list = ["horizontal.png"] * 2 + ["vertical.png"] * 1
    random.shuffle(patch_list)
    

    A new example experiment is pasted here:

    Does this answer your question?

    Best,

    Lotje

  • edited 5:29AM

    Hi Lotje,

    Thanks very much for the info!

    A new piece of 'sound_list' stimuli now plays at the start of each cycle, which does help, but I was wondering if there is anything I can do to get the sound stimuli to play without waiting until the end of the current cycle? (I.e. the sound_list and patch_list stimuli are displayed independently)

    Thanks again for your help :)

  • edited April 2013

    Please disregard the previous comment, I tinkered around with the inline script and now both experiments are working perfectly.

    Thanks! :)

Sign In or Register to comment.