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
1 Like

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!!

This is so awesome!! Helped me so much when creating the same type of N400 sentence reading/comprehension paradigm. The best thread I found for creating an ISI.

Thanks so much!

1 Like

This looks like a great solution. However, I tried to recreate this on Pavlovia and I am getting the following error:

  • TypeError: Cannot read properties of undefined (reading ā€˜pop’)
    Did anyone try to run this code online?