I’m hoping someone could help point me in the right direction here. I designed an experiment that has two tasks running simultaneously and am trying to capture the output of both tasks in a csv file. One task was made in builder and I overlaid the other in the coder. I mimicked the code for logging the button presses from the task made in the builder and applied that to the second task. The code for this is here
t = 0 trialClock.reset() # clock frameN = -1 continueRoutine = True routineTimer.add(2.500000) # update component parameters for each repeat TargetNumber.setText(stim) TargetResponse = event.BuilderKeyResponse() PMtask = event.BuilderKeyResponse() # keep track of which components have finished trialComponents = [TargetNumber, TargetResponse] for thisComponent in trialComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED # -------Start Routine "trial"------- while continueRoutine and routineTimer.getTime() > 0: # get current time t = trialClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) #this is supposed to make the clock if countDown.getTime() > -1: secPos = countDown.getTime() * 6 second.ori = secPos stopwatch.setAutoDraw(True) second.setAutoDraw(True) if countDown.getTime() < PM_time - 3: second.setAutoDraw(False) win.flip() press_space = event.getKeys(keyList=['space']) if 'space' in press_space: second_hand_clock.reset() #record second_hand_clock time as a variable via get time while second_hand_clock.getTime() < 1: stopwatch.setAutoDraw(True) second.setAutoDraw(True) win.flip() if second_hand_clock.getTime()>1: second.setAutoDraw(False) #circle.setAutoDraw(False) win.flip() PMKeys = event.getKeys(keyList=['space', 'right']) # check for quit: if len(PMKeys) > 0: # at least one key was pressed PMtask.keys = PMKeys[-1] # just the last key pressed PMtask.tt = clock.getTime() # *TargetNumber* updates if t >= 0.5 and TargetNumber.status == NOT_STARTED: # keep track of start time/frame for later TargetNumber.tStart = t TargetNumber.frameNStart = frameN # exact frame index TargetNumber.setAutoDraw(True) frameRemains = 0.5 + 2- win.monitorFramePeriod * 0.75 # most of one frame period left if TargetNumber.status == STARTED and t >= frameRemains: TargetNumber.setAutoDraw(False) # *TargetResponse* updates if t >= 0.5 and TargetResponse.status == NOT_STARTED: # keep track of start time/frame for later TargetResponse.tStart = t TargetResponse.frameNStart = frameN # exact frame index TargetResponse.status = STARTED # keyboard checking is just starting win.callOnFlip(TargetResponse.clock.reset) # t=0 on next screen flip event.clearEvents(eventType='keyboard') frameRemains = 0.5 + 1- win.monitorFramePeriod * 0.75 # most of one frame period left if TargetResponse.status == STARTED and t >= frameRemains: TargetResponse.status = STOPPED if TargetResponse.status == STARTED: theseKeys = event.getKeys(keyList=['left', 'down']) # check for quit: if "escape" in theseKeys: endExpNow = True if len(theseKeys) > 0: # at least one key was pressed TargetResponse.keys = theseKeys[-1] # just the last key pressed TargetResponse.rt = TargetResponse.clock.getTime() TargetResponse.tt = clock.getTime() # was this 'correct'? if (TargetResponse.keys == str(corrAns)) or (TargetResponse.keys == corrAns): TargetResponse.corr = 1 else: TargetResponse.corr = 0 # 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 trialComponents: 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 "trial"------- for thisComponent in trialComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # check responses if TargetResponse.keys in ['', , None]: # No response was made TargetResponse.keys=None # was no response the correct answer?! if str(corrAns).lower() == 'none': TargetResponse.corr = 1 # correct non-response else: TargetResponse.corr = 0 # failed to respond (incorrectly) # store data for nbacktrials (TrialHandler) nbacktrials.addData('TargetResponse.keys',TargetResponse.keys) nbacktrials.addData('TargetResponse.corr', TargetResponse.corr) if TargetResponse.keys != None: # we had a response nbacktrials.addData('TargetResponse.rt', TargetResponse.rt) nbacktrials.addData('TargetResponse.tt', TargetResponse.tt) if PMtask.keys != None: # at least one key was pressed nbacktrials.addData('PMtask.keys', PMtask.keys) nbacktrials.addData('PMtask.tt', PMtask.tt) thisExp.nextEntry()
Unfortunately, I get this error (below) and I’m not sure how to correct it. Any assistance would be most appreciated.
AttributeError: 'BuilderKeyResponse' object has no attribute 'tt'```