| Reference | Downloads | Github

N400 task, show sentence word-by-word

Good evening,

I have been trying for well over 2 weeks now in my off time to try and get this program to work. Unfortunately, it is winning :confused:

The goal is for a project that can take a sentence from a .csv, split the sentence into words, and then for every word display the word for 30 frames and then have the screen go black for 20 frames. Once the final word is said, it needs to push off into another text module.

Currently, I have a mess of code, made from putting together pieces of code from other individuals seeking help on the site. I think it might confuse the reader more if I paste all that nonsense than if we try to start from ground zero.

Thank you for any advice

You need two loops around your routine. The outer loop is connected to your conditions file and I’m going to assume that you have a column in that called, say sentence, which contains your sentences, one per trial.

The inner loop is not connected to your conditions file but has a large nReps value that is larger than the number of words in your longest sentence (say, 100).

Insert a code component (from the “custom” component panel). Make sure it is above your text component (you can change the vertical ordering of components by right-clicking on their icons).

In the “begin routine” tab of the code component, put something like this:

# on the first iteration only:
if your_inner_loop_name.thisN == 0:
    # break up the sentence variable into words:
    sentence_list = sentence.split()

# get the next word:
current_word = sentence_list.pop(0)

Put $current_word in the “text” field of your text stimulus component, set to update “every repeat”.

Set that text component to have a duration of 30 frames, and add a black polygon stimulus to start at 30 frames and have a duration of 20 frames.

To terminate the inner loop when the last word has been shown, put something like this in the “end routine” tab:

if len(sentence_list) == 0: # no words left…
    your_inner_loop_name.finished = True

Hi Michael,

Thank you so much for your help!

I now understand, when you said the routine needed 2 loops, you were referring to the actual flow loops. For some reason, I thought it was a coded loop. The way you described worked like a charm, and I am very grateful.

Thanks again!!