OK. Your conditions file only needs a single column, like this:
digits
123
1236
12543
125469
12365478
123654354
Set up your task in Builder like this, with nested loops:
Connect the outer “trials” loop to your conditions file.
The inner loop is not connected to a conditions file. Set it to be sequential and put this in its nReps
field, so that the loop will run as many times on each trial as there are digits to display:
len(list(str(digits)))
i.e. this converts the number into a string of characters, breaks that up into a list of individual characters, and then counts how long that list is to know how many times to run the loop.
In the “learn” routine, insert a Code component (by clicking the “code” icon from the “custom” component panel). In its “begin routine” tab, put something like this:
# only need to do this once, on the first iteration of each trial:
if show_digits.thisN == 0:
# convert the digits from a number into a string of characters then
# break it into a list of individual characters:
sequence = list(str(digits))
correct_answer = list(reversed(sequence))
Insert a “Text” component into the “learn” routine, with a duration of 1 second. Put this in its “Text” field to display the digit corresponding to the the iteration number of the inner loop:
$sequence[show_digits.thisN]
Set that text field to “set every repeat” so that it updates on every iteration.
On the “respond” routine, insert a keyboard component, set to not “force end of routine” and to store “All keys”. Also limit it to just accept the number keys. Also insert a text stimulus. Both of these components should have no fixed duration (so the routine will last indefinitely, until it is ended in code).
Again, insert a code component on this routine. In its “each frame” tab (so that this code runs on every screen refresh, for dynamic updating of the text stimulus, and keyboard responding), put something like this (NB the indenting levels are important, each level of indenting should be four spaces):
answer = your_keyboard_component_name.keys
# only score when the needed number of digits has been typed:
if len(answer) == len(correct_answer):
thisExp.addData('answer', ''.join(answer))
if answer == correct_answer:
thisExp.addData('correct', 1)
else:
thisExp.addData('correct', 0)
continueRoutine = False
In the text stimulus on that routine, put something like this to display the typed results as consecutive digits:
''.join(your_keyboard_component_name.keys)
This time, set this text field to update via “set every frame” to capture the keypresses as they occur.
Now you might find that this ends a bit abruptly as soon as the last number is typed, so the person will hardly see the full response. Let me know if that is an issue and we can discuss how to address it.