Hello! I have a task in the experiment that requires participants to make words out of the letters in another word (i.e. you can make “straw” and “bye” out of “strawberry”). They enter in their answers with the keyboard and have 120 seconds to enter as many as they can. The code works well on the first task (“crustacean” or wordsearch1), but halfway through the second task (“librarian” or wordsearch2), the screen goes black and won’t allow further entries or respond to button presses. It eventually moves on to the end screen. Here’s the code (sorry for formatting):
#------Prepare to start Routine "wordsearch"-------
t = 0
wordsearchClock.reset() # clock
frameN = -1
routineTimer.add(120.000000)
# update component parameters for each repeat
theseKeys=""
shift_flag = False
text_16.alignHoriz ='left'
key_resp_wordsearch = event.BuilderKeyResponse() # create an object of type KeyResponse
key_resp_wordsearch.status = NOT_STARTED
# keep track of which components have finished
wordsearchComponents = []
wordsearchComponents.append(text_16)
wordsearchComponents.append(key_resp_wordsearch)
for thisComponent in wordsearchComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "wordsearch"-------
continueRoutine = True
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = wordsearchClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
n= len(theseKeys)
i = 0
while i < n:
if theseKeys[i] == 'backspace':
inputText = inputText[:-1] # lose the final character
i = i + 1
elif theseKeys[i] == 'space':
inputText += ' '
i = i + 1
elif theseKeys[i] in ['lshift', 'rshift']:
shift_flag = True
i = i + 1
else:
if len(theseKeys[i]) == 1:
# we only have 1 char so should be a normal key,
# otherwise it might be 'ctrl' or similar so ignore it
if shift_flag:
inputText += chr( ord(theseKeys[i]) - ord(' '))
shift_flag = False
else:
inputText += theseKeys[i]
i = i + 1
# *text_16* updates
if t >= 0.0 and text_16.status == NOT_STARTED:
# keep track of start time/frame for later
text_16.tStart = t # underestimates by a little under one frame
text_16.frameNStart = frameN # exact frame index
text_16.setAutoDraw(True)
if text_16.status == STARTED and t >= (120-win.monitorFramePeriod*0.75): #most of one frame period left
text_16.setAutoDraw(False)
if text_16.status == STARTED: # only update if being drawn
text_16.setText((word + '\n' + inputText), log=False)
# *key_resp_wordsearch* updates
if t >= 0.0 and key_resp_wordsearch.status == NOT_STARTED:
# keep track of start time/frame for later
key_resp_wordsearch.tStart = t # underestimates by a little under one frame
key_resp_wordsearch.frameNStart = frameN # exact frame index
key_resp_wordsearch.status = STARTED
# keyboard checking is just starting
win.callOnFlip(key_resp_wordsearch.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if key_resp_wordsearch.status == STARTED and t >= (120-win.monitorFramePeriod*0.75): #most of one frame period left
key_resp_wordsearch.status = STOPPED
if key_resp_wordsearch.status == STARTED:
theseKeys = event.getKeys()
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
key_resp_wordsearch.keys.extend(theseKeys) # storing all keys
key_resp_wordsearch.rt.append(key_resp_wordsearch.clock.getTime())
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in wordsearchComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "wordsearch"-------
for thisComponent in wordsearchComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# let's store the final text string into the results finle...
thisExp.addData('inputText', inputText)
inputText=""
# check responses
if key_resp_wordsearch.keys in ['', [], None]: # No response was made
key_resp_wordsearch.keys=None
# store data for trials_wordsearchfiller (TrialHandler)
trials_wordsearchfiller.addData('key_resp_wordsearch.keys',key_resp_wordsearch.keys)
if key_resp_wordsearch.keys != None: # we had a response
trials_wordsearchfiller.addData('key_resp_wordsearch.rt', key_resp_wordsearch.rt)
thisExp.nextEntry()
# completed 1 repeats of 'trials_wordsearchfiller'
#------Prepare to start Routine "filler_break"-------
t = 0
filler_breakClock.reset() # clock
frameN = -1
# update component parameters for each repeat
key_resp_5 = event.BuilderKeyResponse() # create an object of type KeyResponse
key_resp_5.status = NOT_STARTED
# keep track of which components have finished
filler_breakComponents = []
filler_breakComponents.append(text_22)
filler_breakComponents.append(key_resp_5)
for thisComponent in filler_breakComponents:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "filler_break"-------
continueRoutine = True
while continueRoutine:
# get current time
t = filler_breakClock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text_22* updates
if t >= 0.0 and text_22.status == NOT_STARTED:
# keep track of start time/frame for later
text_22.tStart = t # underestimates by a little under one frame
text_22.frameNStart = frameN # exact frame index
text_22.setAutoDraw(True)
# *key_resp_5* updates
if t >= 0.0 and key_resp_5.status == NOT_STARTED:
# keep track of start time/frame for later
key_resp_5.tStart = t # underestimates by a little under one frame
key_resp_5.frameNStart = frameN # exact frame index
key_resp_5.status = STARTED
# keyboard checking is just starting
win.callOnFlip(key_resp_5.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if key_resp_5.status == STARTED:
theseKeys = event.getKeys(keyList=['space'])
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
key_resp_5.keys = theseKeys[-1] # just the last key pressed
key_resp_5.rt = key_resp_5.clock.getTime()
# a response ends the routine
continueRoutine = False
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in filler_breakComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "filler_break"-------
for thisComponent in filler_breakComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# check responses
if key_resp_5.keys in ['', [], None]: # No response was made
key_resp_5.keys=None
# store data for thisExp (ExperimentHandler)
thisExp.addData('key_resp_5.keys',key_resp_5.keys)
if key_resp_5.keys != None: # we had a response
thisExp.addData('key_resp_5.rt', key_resp_5.rt)
thisExp.nextEntry()
# the Routine "filler_break" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# set up handler to look after randomisation of conditions etc
trials_wordsearch2 = data.TrialHandler(nReps=1, method='random',
extraInfo=expInfo, originPath=-1,
trialList=data.importConditions('wordsearchlibrarian.xlsx'),
seed=None, name='trials_wordsearch2')
thisExp.addLoop(trials_wordsearch2) # add the loop to the experiment
thisTrials_wordsearch2 = trials_wordsearch2.trialList[0] # so we can initialise stimuli with some values
# abbreviate parameter names if possible (e.g. rgb=thisTrials_wordsearch2.rgb)
if thisTrials_wordsearch2 != None:
for paramName in thisTrials_wordsearch2.keys():
exec(paramName + '= thisTrials_wordsearch2.' + paramName)
for thisTrials_wordsearch2 in trials_wordsearch2:
currentLoop = trials_wordsearch2
# abbreviate parameter names if possible (e.g. rgb = thisTrials_wordsearch2.rgb)
if thisTrials_wordsearch2 != None:
for paramName in thisTrials_wordsearch2.keys():
exec(paramName + '= thisTrials_wordsearch2.' + paramName)
#------Prepare to start Routine "wordsearch_2"-------
t = 0
wordsearch_2Clock.reset() # clock
frameN = -1
routineTimer.add(120.000000)
# update component parameters for each repeat
theseKeys=""
shift_flag = False
text_16.alignHoriz ='left'
key_resp_wordsearch_2 = event.BuilderKeyResponse() # create an object of type KeyResponse
key_resp_wordsearch_2.status = NOT_STARTED
# keep track of which components have finished
wordsearch_2Components = []
wordsearch_2Components.append(text_21)
wordsearch_2Components.append(key_resp_wordsearch_2)
for thisComponent in wordsearch_2Components:
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
#-------Start Routine "wordsearch_2"-------
continueRoutine = True
while continueRoutine and routineTimer.getTime() > 0:
# get current time
t = wordsearch_2Clock.getTime()
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
n= len(theseKeys)
i = 0
while i < n:
if theseKeys[i] == 'backspace':
inputText = inputText[:-1] # lose the final character
i = i + 1
elif theseKeys[i] == 'space':
inputText += ' '
i = i + 1
elif theseKeys[i] in ['lshift', 'rshift']:
shift_flag = True
i = i + 1
else:
if len(theseKeys[i]) == 1:
# we only have 1 char so should be a normal key,
# otherwise it might be 'ctrl' or similar so ignore it
if shift_flag:
inputText += chr( ord(theseKeys[i]) - ord(' '))
shift_flag = False
else:
inputText += theseKeys[i]
i = i + 1
# *text_21* updates
if t >= 0.0 and text_21.status == NOT_STARTED:
# keep track of start time/frame for later
text_21.tStart = t # underestimates by a little under one frame
text_21.frameNStart = frameN # exact frame index
text_21.setAutoDraw(True)
if text_21.status == STARTED and t >= (120-win.monitorFramePeriod*0.75): #most of one frame period left
text_21.setAutoDraw(False)
if text_21.status == STARTED: # only update if being drawn
text_21.setText((word + '\n' + inputText), log=False)
# *key_resp_wordsearch_2* updates
if t >= 0.0 and key_resp_wordsearch_2.status == NOT_STARTED:
# keep track of start time/frame for later
key_resp_wordsearch_2.tStart = t # underestimates by a little under one frame
key_resp_wordsearch_2.frameNStart = frameN # exact frame index
key_resp_wordsearch_2.status = STARTED
# keyboard checking is just starting
win.callOnFlip(key_resp_wordsearch_2.clock.reset) # t=0 on next screen flip
event.clearEvents(eventType='keyboard')
if key_resp_wordsearch_2.status == STARTED and t >= (120-win.monitorFramePeriod*0.75): #most of one frame period left
key_resp_wordsearch_2.status = STOPPED
if key_resp_wordsearch_2.status == STARTED:
theseKeys = event.getKeys()
# check for quit:
if "escape" in theseKeys:
endExpNow = True
if len(theseKeys) > 0: # at least one key was pressed
key_resp_wordsearch_2.keys.extend(theseKeys) # storing all keys
key_resp_wordsearch_2.rt.append(key_resp_wordsearch_2.clock.getTime())
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in wordsearch_2Components:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# check for quit (the Esc key)
if endExpNow or event.getKeys(keyList=["escape"]):
core.quit()
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
#-------Ending Routine "wordsearch_2"-------
for thisComponent in wordsearch_2Components:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
# let's store the final text string into the results finle...
thisExp.addData('inputText', inputText)
inputText=""
# check responses
if key_resp_wordsearch_2.keys in ['', [], None]: # No response was made
key_resp_wordsearch_2.keys=None
# store data for trials_wordsearch2 (TrialHandler)
trials_wordsearch2.addData('key_resp_wordsearch_2.keys',key_resp_wordsearch_2.keys)
if key_resp_wordsearch_2.keys != None: # we had a response
trials_wordsearch2.addData('key_resp_wordsearch_2.rt', key_resp_wordsearch_2.rt)
thisExp.nextEntry()
# completed 1 repeats of 'trials_wordsearch2'
I just copied the code from the first task for the second, so I don’t understand why this is not working. Any advice or help on this would be much appreciated!