---
API: 2
Citation: 'Raymond, J. E., Shapiro, K. L., & Arnell, K. M. (1992). Temporary suppression
  of visual processing in an RSVP task: An attentional blink? *Journal of Experimental
  Psychology: Human Perception and Performance*, *18*(3), 849-860. <http://doi.org/10.1037/0096-1523.18.3.849>'
Description: Experiment from the attentional-blink tutorial
OpenSesame: 3.0.0~pre2
Platform: posix
Title: Attentional blink
---
set width 1024
set title "Attentional blink"
set synth_backend "legacy"
set subject_parity "even"
set subject_nr 0
set start "experiment"
set sampler_backend "legacy"
set mouse_backend "psycho"
set keyboard_backend "psycho"
set height 768
set foreground "black"
set font_size 32
set font_italic "no"
set font_family "mono"
set font_bold "no"
set description "Based on Experiment 2 from Raymond et al. (1992, JEP HPP)"
set coordinates "relative"
set compensation 0
set canvas_backend "psycho"
set bidi "no"
set background "gray"

define inline_script RSVP
	___run__
	# Loop through all canvas objects and present them, separate by a blank canvas
	for letter_canvas in letter_canvas_list:
		letter_canvas.show()
		clock.sleep(var.letter_dur)
		blank_canvas.show()
		clock.sleep(var.isi)
	__end__
	___prepare__
	# We're going to use the random and string modules
	import random
	import string
	
	# Set variables that are fixed throughout the experiment
	var.T1_color = 'white'
	var.letter_dur = 10
	var.isi = 70
	var.max_lag = 8
	
	# Choose a random position for the T1, and use this to determine the length of
	# the stream
	var.T1_pos = random.randint(7, 15)
	var.stream_len = var.T1_pos + var.max_lag + 1
	
	# Randomly sample letters from all uppercase letters, except for the X, which
	# is used for the T2 (when present).
	letters = list(string.uppercase)
	letters.remove('X')
	stim_list = random.sample(letters, var.stream_len)
	
	# Determine the T1
	var.T1 = stim_list[var.T1_pos].lower()
	
	# Replace the letter at the T2 position by an X
	if var.T2_present == 'y':
		var.T2_pos = var.T1_pos + var.lag
		stim_list[var.T2_pos] = 'X'
	
	# Create a list of canvas objects, one for each letter. For the T1, we
	# explicitly need to set color, because it has a different color from the other
	# stimuli.
	letter_canvas_list = []
	for i, stim in enumerate(stim_list):
		letter_canvas = canvas()
		if i == var.T1_pos:
			color = var.T1_color
		else:
			color = var.foreground
		letter_canvas.text(stim, color=color)
		letter_canvas_list.append(letter_canvas)
		
	# Also create a blank canvas for the inter-stimulus interval
	blank_canvas = canvas()
	
	# Print the stimulus list to the debug window, so we can inspect it
	print(stim_list)
	__end__

define notepad about_this_template
	__note__
	Probe = X
	Target is white
	Probe position relative to target: 0-8. For 0, target is white X
	Task: Name white letter and indicate whether probe was present
	Letters randomly chosen from all letters in alphabet
	Nr of pre-target letters random between 7 and 15
	Nr of post-target letters always 8
	Target dur = 15 ms
	ISI (offset - onset) = 75 ms
	
	Trial start indicated with mouse click
	Trial starts with a 180 ms fixation dot
	
	In the original experiment, ppts gave verbal responses.
	In the original experiment, each trial was started with a mouseclick.
	__end__
	set description "Some pointers to help you gest started!"

define sketchpad ask_T1
	set start_response_interval "no"
	set reset_variables "no"
	set duration 0
	set description "Displays stimuli"
	draw textline 0 0 "Which letter was <span color=white>white</span>?" center=1 color="black" font_family="mono" font_size=18 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sketchpad ask_T2
	set reset_variables "no"
	set duration 0
	draw textline 0 0 "Did you see an X?<br />(y/n)" center=1 color="black" font_family="mono" font_size=18 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define inline_script assertions
	set _run ""
	___prepare__
	# These are sanity checks: They are things that should be true, and, if not,
	# indicate a bug in the experiment somewhere.
	assert(var.condition in ['experimental', 'control'])
	assert(var.T2_present in ['y', 'n'])
	assert(var.lag in ['']+range(0,9))
	assert((var.lag == '') != (var.T2_present == 'y'))
	__end__

define loop block_loop
	set skip 0
	set repeat 1
	set order "random"
	set offset "no"
	set item "trial_sequence"
	set description "A single block of trials"
	set cycles 18
	set column_order "lag;T2_present"
	set break_if "never"
	setcycle 0 T2_present "y"
	setcycle 0 lag "0"
	setcycle 1 T2_present "y"
	setcycle 1 lag "1"
	setcycle 2 T2_present "y"
	setcycle 2 lag "2"
	setcycle 3 T2_present "y"
	setcycle 3 lag "3"
	setcycle 4 T2_present "y"
	setcycle 4 lag "4"
	setcycle 5 T2_present "y"
	setcycle 5 lag "5"
	setcycle 6 T2_present "y"
	setcycle 6 lag "6"
	setcycle 7 T2_present "y"
	setcycle 7 lag "7"
	setcycle 8 T2_present "y"
	setcycle 8 lag "8"
	setcycle 9 T2_present "n"
	setcycle 9 lag ""
	setcycle 10 T2_present "n"
	setcycle 10 lag ""
	setcycle 11 T2_present "n"
	setcycle 11 lag ""
	setcycle 12 T2_present "n"
	setcycle 12 lag ""
	setcycle 13 T2_present "n"
	setcycle 13 lag ""
	setcycle 14 T2_present "n"
	setcycle 14 lag ""
	setcycle 15 T2_present "n"
	setcycle 15 lag ""
	setcycle 16 T2_present "n"
	setcycle 16 lag ""
	setcycle 17 T2_present "n"
	setcycle 17 lag ""
	run trial_sequence

define sequence block_sequence
	set flush_keyboard "yes"
	set description "A sequence containing a single block of trials followed by feedback to the participant"
	run instructions_experimental "[condition] = experimental"
	run instructions_control "[condition] = control"
	run reset_feedback "always"
	run block_loop "always"
	run feedback "always"

define inline_script counterbalance
	set _run ""
	___prepare__
	if var.subject_parity == 'even':
		var.condition1 = 'experimental'
		var.condition2 = 'control'
	else:
		var.condition1 = 'control'
		var.condition2 = 'experimental'
	__end__

define sketchpad end_of_experiment
	set start_response_interval "no"
	set duration "keypress"
	set description "A sketchpad notifying the participant that the experiment is finished"
	draw textline 0 0 "Press any key to exit" center=1 color="white" font_family="mono" font_size=18 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sketchpad end_of_practice
	set start_response_interval "no"
	set reset_variables "no"
	set duration "keypress"
	set description "A sketchpad notifying the participant that the practice phase is finished"
	draw textline 0 0 "Press any key to continue" center=1 color="white" font_family="mono" font_size=18 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sequence experiment
	set flush_keyboard "yes"
	set description "The main sequence of the experiment"
	run counterbalance "always"
	run about_this_template "always"
	run instructions "always"
	run practice_loop "always"
	run end_of_practice "always"
	run experimental_loop "always"
	run end_of_experiment "always"

define loop experimental_loop
	set skip 0
	set repeat 1
	set order "sequential"
	set offset "no"
	set item "block_sequence"
	set description "A loop containing one or more experimental blocks"
	set cycles 10
	set column_order "practice;condition;block_repeat"
	set break_if "never"
	setcycle 0 block_repeat "2"
	setcycle 0 practice "no"
	setcycle 0 condition "[condition1]"
	setcycle 1 block_repeat "2"
	setcycle 1 practice "no"
	setcycle 1 condition "[condition1]"
	setcycle 2 block_repeat "2"
	setcycle 2 practice "no"
	setcycle 2 condition "[condition1]"
	setcycle 3 block_repeat "2"
	setcycle 3 practice "no"
	setcycle 3 condition "[condition1]"
	setcycle 4 block_repeat "2"
	setcycle 4 practice "no"
	setcycle 4 condition "[condition1]"
	setcycle 5 block_repeat "2"
	setcycle 5 practice "no"
	setcycle 5 condition "[condition2]"
	setcycle 6 block_repeat "2"
	setcycle 6 practice "no"
	setcycle 6 condition "[condition2]"
	setcycle 7 block_repeat "2"
	setcycle 7 practice "no"
	setcycle 7 condition "[condition2]"
	setcycle 8 block_repeat "2"
	setcycle 8 practice "no"
	setcycle 8 condition "[condition2]"
	setcycle 9 block_repeat "2"
	setcycle 9 practice "no"
	setcycle 9 condition "[condition2]"
	run block_sequence

define feedback feedback
	set reset_variables "yes"
	set duration "keypress"
	set description "Provides feedback to the participant"
	draw textline 0 0 "<b>End of block</b><br /><br />Your accuracy was [acc] %<br /><br />Press any key to continue ..." center=1 color="white" font_family="sans" font_size=24 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sketchpad fixation
	set reset_variables "no"
	set duration 995
	draw fixdot 0 0 color="white" style="default" z_index=0 show_if="always"

define sketchpad instructions
	set start_response_interval "no"
	set reset_variables "no"
	set duration "keypress"
	set description "A sketchpad containing the instructions for the participant"
	draw textline 0 0 "Press any key to begin!" center=1 color="white" font_family="mono" font_size=18 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sketchpad instructions_control
	set reset_variables "no"
	set duration "keypress"
	draw textline 0 0 "INSTRUCTIONS<br /><br />You will see a series of letters. Please report only<br /><br /><b>whether an 'X' was present</b><br /><br />Press any key to begin ..." center=1 color="black" font_family="sans" font_size=24 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define sketchpad instructions_experimental
	set reset_variables "no"
	set duration "keypress"
	draw textline 0 -32 "INSTRUCTIONS<br /><br />You will see a series of letters. Please report<br /><br /><b>the identity of the <span color=white>white</span> letter</b><br /><br />and<br /><br /><b>whether an 'X' was present</b><br /><br />Press any key to begin ..." center=1 color="black" font_family="sans" font_size=24 font_bold="no" font_italic="no" html="yes" z_index=0 show_if="always"

define logger logger
	set description "Logs experimental data"
	set auto_log "yes"

define loop practice_loop
	set skip 0
	set repeat 1
	set order "sequential"
	set offset "no"
	set item "block_sequence"
	set description "A loop containing one or more practice blocks"
	set cycles 2
	set column_order "practice;condition;block_repeat"
	set break_if "never"
	setcycle 0 block_repeat "0.5"
	setcycle 0 practice "yes"
	setcycle 0 condition "[condition1]"
	setcycle 1 block_repeat "0.5"
	setcycle 1 practice "yes"
	setcycle 1 condition "[condition2]"
	run block_sequence

define reset_feedback reset_feedback

define keyboard_response response_T1
	set timeout "infinite"
	set flush "yes"
	set duration "keypress"
	set description "Collects keyboard responses"
	set correct_response "[T1]"

define keyboard_response response_T2
	set timeout "infinite"
	set flush "yes"
	set duration "keypress"
	set correct_response "[T2_present]"
	set allowed_responses "y;n"

define sequence trial_sequence
	set flush_keyboard "yes"
	set description "A single trial"
	run assertions "always"
	run fixation "always"
	run RSVP "always"
	run ask_T1 "[condition] = experimental"
	run response_T1 "[condition] = experimental"
	run ask_T2 "always"
	run response_T2 "always"
	run logger "always"

