---
API: 2.1
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.3.0a49
Platform: posix
Title: Attentional blink
---
set width 1024
set uniform_coordinates no
set title "Attentional blink"
set subject_parity even
set subject_nr 0
set start experiment
set sound_sample_size -16
set sound_freq 48000
set sound_channels 2
set sound_buf_size 1024
set round_decimals 2
set height 768
set fullscreen no
set form_clicks no
set foreground black
set font_underline no
set font_size 32
set font_italic no
set font_family mono
set font_bold no
set experiment_path "/home/sebastiaan/git/OpenSesame/opensesame_extensions/example_experiments/examples/attentional_blink"
set disable_garbage_collection yes
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
	set description "Executes Python code"
	___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.ascii_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 center=1 color=black font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Which letter was <span color=white>white</span>?" x=0 y=0 z_index=0

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

define inline_script assertions
	set description "Executes Python code"
	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 [''] + list(range(0, 9)))
	assert((var.lag == '') != (var.T2_present == 'y'))
	__end__

define loop block_loop
	set source_file ""
	set source table
	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 continuous no
	set column_order "lag;T2_present"
	set break_if_on_first yes
	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 description "Executes Python code"
	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 center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Press any key to exit" x=0 y=0 z_index=0

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 center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Press any key to continue" x=0 y=0 z_index=0

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 source_file ""
	set source table
	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 continuous no
	set column_order "practice;condition;block_repeat"
	set break_if_on_first yes
	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 center=1 color=white font_bold=no font_family=sans font_italic=no font_size=24 html=yes show_if=always text="<b>End of block</b><br /><br />Your accuracy was [acc] %<br /><br />Press any key to continue ..." x=0 y=0 z_index=0

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

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 center=1 color=white font_bold=no font_family=mono font_italic=no font_size=18 html=yes show_if=always text="Press any key to begin!" x=0 y=0 z_index=0

define sketchpad instructions_control
	set reset_variables no
	set duration keypress
	set description "Displays stimuli"
	draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=24 html=yes show_if=always text="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 ..." x=0 y=0 z_index=0

define sketchpad instructions_experimental
	set reset_variables no
	set duration keypress
	set description "Displays stimuli"
	draw textline center=1 color=black font_bold=no font_family=sans font_italic=no font_size=24 html=yes show_if=always text="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 ..." x=0 y=-32 z_index=0

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

define loop practice_loop
	set source_file ""
	set source table
	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 continuous no
	set column_order "practice;condition;block_repeat"
	set break_if_on_first yes
	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
	set description "Resets the feedback variables, such as 'avg_rt' and 'acc'"

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

define keyboard_response response_T2
	set timeout infinite
	set flush yes
	set event_type keypress
	set duration keypress
	set description "Collects keyboard responses"
	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

