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

**URL:** <https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684>\
**Category:** Builder\
**Created:** [October 30, 2018, 7:11pm UTC](https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684 "2018-10-30T19:11:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozgae](https://avatars.discourse-cdn.com/v4/letter/o/82dd89/32.png) [@ozgae](https://discourse.psychopy.org/u/ozgae)\
**Post date:** [October 30, 2018, 7:11pm UTC](https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684/1 "2018-10-30T19:11:32Z")

</div>

**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:

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

```

At Each Frame:

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

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [October 30, 2018, 11:10pm UTC](https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684/2 "2018-10-30T23:10:57Z")

</div>

Just add the current word to whatever is already there:

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

---

<div class="post-metadata">

**Author:** ![ozgae](https://avatars.discourse-cdn.com/v4/letter/o/82dd89/32.png) [@ozgae](https://discourse.psychopy.org/u/ozgae)\
**Post date:** [October 31, 2018, 12:51am UTC](https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684/3 "2018-10-31T00:51:24Z")

</div>

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

 ![37%20PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/6/463c89339b43b83fe79fc5577a08f1cd7651b2fe.jpeg)

---

<div class="post-metadata">

**Author:** ![ozgae](https://avatars.discourse-cdn.com/v4/letter/o/82dd89/32.png) [@ozgae](https://discourse.psychopy.org/u/ozgae)\
**Post date:** [October 31, 2018, 1:37am UTC](https://discourse.psychopy.org/t/language-experiment-word-by-word-sentence-presentation-with-keeping-the-previous-words/5684/4 "2018-10-31T01:37:38Z")

</div>

Problem solved!

At Each Frame

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

```
