Hi all!
I have text, sound and a key response in each trial of my experiment. Following the sound, I would like for participants to have 1 second following the end of the auditory stimulus to respond using their keyboard although they can also respond during the stimulus. I am using core.wait(1)
to do so, although it just ‘freezes’ on the text on screen (on the first trial) and I am unable to press anything other than ‘esc’ to stop this.
I saw someone had a similar issue, however, I don’t think my screen is actually freezing, just that I have made an error coding the wait time. The relevant code is below (‘core.wait’ is just above ‘check for quit’) . I would greatly appreciate any help!
trial_sound.setSound(Stimulus, hamming=True)
trial_sound.setVolume(1, log=False)
# keep track of which components have finished
trial_Components = [trial_text, trial_key_resp, trial_sound]
for thisComponent in trial_Components:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "trial"-------
while continueRoutine:
# get current time
t = trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *trial_text* updates
if trial_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
trial_text.frameNStart = frameN # exact frame index
trial_text.tStart = t # local t and not account for scr refresh
trial_text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(trial_text, 'tStartRefresh') # time at next scr refresh
trial_text.setAutoDraw(True)
# *trial_key_resp* updates
waitOnFlip = False
if trial_key_resp.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
trial_key_resp.frameNStart = frameN # exact frame index
trial_key_resp.tStart = t # local t and not account for scr refresh
trial_key_resp.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(trial_key_resp, 'tStartRefresh') # time at next scr refresh
trial_key_resp.status = STARTED
# keyboard checking is just starting
waitOnFlip = True
win.callOnFlip(trial_key_resp.clock.reset) # t=0 on next screen flip
win.callOnFlip(trial_key_resp.clearEvents, eventType='keyboard') # clear events on next screen flip
if trial_key_resp.status == STARTED:
# is it time to stop? (based on global clock, using actual start)
if tThisFlipGlobal > trial_key_resp.tStartRefresh + 0.0-frameTolerance:
# keep track of stop time/frame for later
trial_key_resp.tStop = t # not accounting for scr refresh
trial_key_resp.frameNStop = frameN # exact frame index
win.timeOnFlip(trial_key_resp, 'tStopRefresh') # time at next scr refresh
trial_key_resp.status = FINISHED
if trial_key_resp.status == STARTED and not waitOnFlip:
theseKeys = trial_key_resp.getKeys(keyList=['left', 'right'], waitRelease=False)
_trial_key_resp_allKeys.extend(theseKeys)
if len(_trial_key_resp_allKeys):
trial_key_resp.keys = _trial_key_resp_allKeys[-1].name # just the last key pressed
trial_key_resp.rt = _trial_key_resp_allKeys[-1].rt
# was this correct?
if (trial_key_resp.keys == str(corrAns)) or (trial_key_resp.keys == corrAns):
trial_key_resp.corr = 1
else:
trial_key_resp.corr = 0
# a response ends the routine
continueRoutine = False
# start/stop trial_sound
if trial_sound.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
trial_sound.frameNStart = frameN # exact frame index
trial_sound.tStart = t # local t and not account for scr refresh
trial_sound.tStartRefresh = tThisFlipGlobal # on global time
trial_sound.play(when=win) # sync with win flip
core.wait(1)
win.close()
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# 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 trial_Components:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()