Howdy, Stranger!

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

Supported by

Inline python command to draw text stimuli to search display


I'm working on coding a distraction task where participants are to ignore the letter distractor and respond to the integer target (0-9) as being odd or even. I have the code for another program in my lab that used circle and square stimuli, but I'm having difficulty converting it to get my randomly selected digit and/or letter to appear on the screen at a random location of 10 options around a circular shape. I'm pretty new to OpenSesame, but I've been playing with this code for over a month now on and off and figure now's a great time to seek help.

Here's my lists I define as constants at the beginning.

target_dig = ['0','1','2','3','4','5','6','7','8','9'] # change to target digits

#creates list of uppercase alphabet to be used as distractor stimuli
distract_stim = list(string.ascii_uppercase)

# Distractor presence
distractor = ['present','absent']

Then the functions I have in another script after just to select the digit/letter and choose distractor location.

def calculate_distractor_position(row):
	if row.distractor == 'present':
		# just randomly choose a distractor location that's not the target location
		distractor_pos = random.choice(list(set(positions) - {row.target_pos}))
		distractor_pos = None
		return distractor_pos 

def draw_distr(row):
	if row.distractor == 'present':
		distr = random.choice(distract_stim)
		return distr

def draw_target(cnvs, x, y):
	stim = random.choice(target_dig)
	return stim

And then in the actual trial_sequence script in the trial loop, the creation of the canvas with the supposed functions.

# determining target position and color
var.target_pos = row.target_pos
var.target_color = row.target_color

# setting distractor color and position different from target 
var.distractor = row.distractor
if var.distractor == 'present':
	var.distractor_pos = row.distractor_pos
	var.distractor_color = list(set(colors)-set([var.target_color]))[0]
	var.distractor_pos = None
	var.distractor_color = None

# creating canvas 

target_canvas = stimuli.Canvas(size=(1024,768))

for pos, (x, y) in enumerate(xy_circle(set_size, eccentricity)):
	if pos == var.target_pos:
		draw_target(target_canvas, x, y) 
	elif pos == var.distractor_pos:
		draw_distr(target_canvas, x, y, color=var.distractor_color)

The functions seem simplistic, but I think they should work fine in actually selecting the random letter or digit, but it's the display of the stimuli around a circle I'm really having issues with. There's a lot of code in between all of these but this is the most relevant to the main issue and at this point I'll take any advice there is to offer. Thanks!!!


  • Additional: It runs with the instructions and fixation cross through trials, but there's no stimuli that show up to respond to. Python also keeps crashing during these runs, so I only get to go through a few trials at a time before it does. It's been crashing on two different devices at various timepoints whenever I try to quick run .

  • Hi,

    Your drawing function does no drawing, but target selection. Use these two functions instead:

    def select_target(target_dig):
        stim = random.choice(target_dig)
        return stim
    def draw_target(cnvs, x, y,text):

    Does that help?

Sign In or Register to comment.