I have a PsychoPy routine that is intended to act as a memory object-span test. In one loop, the software presents an object (a single text character) followed by a user task multiple times. The software remembers the string of characters, and later asks the user to enter the characters as they were presented. This sequence (loop of tasks followed by character recall) is itself presented several times in a larger loop.
The characters are chosen randomly.
I would like to record, either in the CSV file which PsychoPy generates, or a log file of some sort, the characters that the user is entering. How does one do that in the PsychoPy graphical interface system?
The code block used to record the character sequences is:
Begin Routine
givenAnswer = ""
returnPressed = False
R_memPrompt.setText("Please enter characters in the order they were presented, then hit 'Return':")
R_memPrompt.draw()
win.flip()
Each Frame
loopTest = True userInput = ""
if returnPressed == False:
while loopTest == True:
response = event.waitKeys(keyList=['a','b','c','d','e','f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'return', 'backspace', 'left'])
if response[0] == 'return':
loopTest = False
returnPressed = True
continueRoutine = False
elif response[0] == 'backspace':
userInput = userInput[:-1]
userInput = userInput.upper()
R_disp.setText(userInput)
R_disp.draw()
win.flip()
else:
userInput = userInput + response[0]
userInput = userInput.upper()
R_disp.setText(userInput)
R_disp.draw()
win.flip()
End Routine
givenAnswer = givenAnswer + userInput
A later routine has, as its Begin Routine
if memorySequence == givenAnswer: # memorySequence is the prior record of memory characters
# do some stuff
else:
# do some other stuff
Crude (it is a prototype) but the intent of the Each Frame section is simply to reflect characters as they are written to the screen, through the R_disp text stimulus, while allowing the user to backspace and not worry about case sensitivity. The final answer ends up in givenAnswer, and is later compared to memorySequence which was built up previously.
I would like to dump the contents of those variables, memorySequence and givenAnswer to the CSV file or some log file so that I do not lose the information.
Is there a way to do this?
Certainly. In the "End Routine" tab of your code component, put something like this:
thisExp.addData("sequence", memorySequence)
thisExp.addData("answer", givenAnswer)
This will add two new columns to your data file, with column headers of whatever literal values you put in the quotes.