Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Generated by OpenSesame 0.27 (Frisky Freud)
- # Mon Jan 21 15:14:35 2013 (posix)
- # <http://www.cogsci.nl/opensesame>
- set foreground "white"
- set subject_parity "even"
- set description "A template containing a practice and an experimental phase"
- set title "Extended template"
- set compensation "0"
- set coordinates "relative"
- set height "768"
- set mouse_backend "xpyriment"
- set width "1024"
- set sampler_backend "legacy"
- set keyboard_backend "legacy"
- set background "black"
- set subject_nr "0"
- set canvas_backend "xpyriment"
- set start "experiment"
- set synth_backend "legacy"
- define loop patch_loop
- set repeat "1"
- set description "A single block of trials"
- set skip "0"
- set offset "no"
- set item "stream_of_patches"
- set column_order ""
- set cycles "1"
- set order "random"
- run stream_of_patches
- define sequence vigilance_task
- set flush_keyboard "yes"
- set description "A sequence containing a single block of trials followed by feedback to the participant"
- run patch_loop "always"
- define form_multiple_choice mc
- set allow_multiple "yes"
- set description "A simple multiple choice item"
- set question "Do you like bunnies?"
- set button_text "Ok"
- set advance_immediately "yes"
- set form_title "Form title"
- set form_var "form_response"
- __options__
- Yes
- No
- Maybe
- __end__
- define reset_feedback _reset_feedback
- define sequence stream_of_patches
- set flush_keyboard "yes"
- set description "A single trial"
- run mc "never"
- run inline_script "always"
- run logger "never"
- define loop experimental_loop
- set repeat "1"
- set description "A loop containing one or more experimental blocks"
- set item "vigilance_task"
- set column_order "practice"
- set cycles "1"
- set order "random"
- setcycle 0 practice "no"
- run vigilance_task
- define sequence experiment
- set flush_keyboard "yes"
- set description "The main sequence of the experiment"
- run constants "always"
- run experimental_loop "always"
- define inline_script inline_script
- ___run__
- 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")
- __end__
- ___prepare__
- # Create a canvas item to display the stimulus:
- global my_canvas
- from openexp.canvas import canvas
- my_canvas = canvas(exp, bgcolor = "#7F7F7F")
- # Create a sampler item that we'll need for playing
- # the sounds.
- global my_sampler
- from openexp.sampler import sampler
- # Determine the to-be-played sound file:
- sound_stim = sound_list.pop()
- sound_file = exp.get_file(sound_stim)
- my_sampler = sampler(exp, sound_file)
- __end__
- set description "Executes Python code"
- define logger logger
- set ignore_missing "yes"
- set description "Logs experimental data"
- set auto_log "yes"
- set use_quotes "yes"
- define inline_script constants
- set _run ""
- ___prepare__
- # 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 visual stimulus list and the auditory stimulus list.
- global patch_list
- patch_list = ["horizontal.png"] * 10 + ["vertical.png"] * 1
- random.shuffle(patch_list)
- global sound_list
- sound_list = ["sound1.wav", "sound2.wav"]
- random.shuffle(patch_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
- __end__
- set description "Executes Python code"
- define reset_feedback reset_feedback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement