psychopy.org | Reference | Downloads | Github

Language Experiment: Word by word sentence presentation with keeping the previous words

OS (e.g. Win10): MAC OS 10.13.6
PsychoPy version (e.g. 1.84.x): 3
Standard Standalone? (y/n) y If not then what?:

Hi all,
I am trying to present my sentence stimuli incrementally. What I am trying to do is building the sentence by using a word by word presentation keeping all the previous words on the screen. Here is what I mean:
When
When the
When the lion…

What did you try to make it work?:
So far, I am able to present the words one by one, one word at a time: i.e. before each word appears the previous one disappears.
I used the following code from a previous topic:
Coder component:

At Begin Routine:

words = sentence.split()
numWords = len(words)
totalDuration = numWords * 0.5
currentWordIndex = -1

At Each Frame:

checkIndex = int(t/0.5)
if checkIndex < numWords:
   if checkIndex != currentWordIndex:
      currentWordIndex = checkIndex
      text.setText(words[currentWordIndex]) # update to the current word

My sense is that at Each Frame, I can modify the text.setText() command using the currentWordIndex by creating something like “word1+word2+…” but I don’t know how to exactly do that!

Any help would be appreciated. Thanks!

Just add the current word to whatever is already there:

text.text = text.text + words[currentWordIndex]

Thank you Michael but it didn’t work unfortunately. It just “doubles” the word presentation like below.

Problem solved!

At Each Frame

checkIndex = int(t/0.5)
if checkIndex < numWords:
   if checkIndex != currentWordIndex:
      currentWordIndex = checkIndex
      text.setText(' '.join(words[0:(currentWordIndex+1)])) # Space is inserted between ''