# Loop & text componet

**URL:** <https://discourse.psychopy.org/t/loop-text-componet/36235>\
**Category:** Builder\
**Created:** [August 29, 2023, 12:37pm UTC](https://discourse.psychopy.org/t/loop-text-componet/36235 "2023-08-29T12:37:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawon](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@dawon](https://discourse.psychopy.org/u/dawon)\
**Post date:** [August 29, 2023, 12:37pm UTC](https://discourse.psychopy.org/t/loop-text-componet/36235/1 "2023-08-29T12:37:14Z")

</div>

If this template helps then use it. If not then just delete and start from scratch.

**OS** (e.g. Win10): Win11  
**PsychoPy version** (e.g. 1.84.x): 2023.1.3

I’m going to use Loop. First of all, the excel file I have is like this, ‘sentence’ is the variable name, and the unfinished sentences below are the stimuli.(figure 1)

![1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/8/3/830b7de5c38561786805edc1a5aac95a641caf1d.png)  
](https://)

And in the previous trial of loop, I set the code for participants to enter names in the variable ‘name’. (figure 1-1)

 ![1-1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/9/c91e88e7f02a19dc134206026757deff5ee766e1.png)

So I wanted the name + sentence to come out when the loop was implemented. For example, if the name you entered is John, then John is happy. So I tried a total of three things.

1. Enter $name + $sentence directly into text component  
 → Just ‘name+$sentence’ comes out in screen

2. Add code component, add code to Begin Routine. And enter $text2 in text component. I’ve done both, but neither of them works(of course, I text $text2 in text component)  
 → It said ‘text2 is undefined’

```auto
text2 = "{} {}".format(name, sentence)

```

or

```auto
sentence=trials['sentence']
text2 = "{} {}".format(name, sentence)

```

1. When I modified the code in coder, it executed well. However, the modification was not reflected in the builder. I want to know the solution.

```auto
if thisTrial != None:
    for paramName in thisTrial:
        exec('{} = thisTrial[paramName]'.format(paramName))

for thisTrial in trials:
    currentLoop = trials
    # abbreviate parameter names if possible (e.g. rgb = thisTrial.rgb)
    if thisTrial != None:
        for paramName in thisTrial:
            exec('{} = thisTrial[paramName]'.format(paramName))
    
    # --- Prepare to start Routine "real" ---
    continueRoutine = True
    # update component parameters for each repeat
    sentence = trials['sentence']
    full_text = f"{names} {sentence}"
    text_7.setText(full_text)
    slider.reset()

  

```

(This is successful code)

How can I put the ‘John is happy’ sentence on the screen that I want?  
Please help me, I’ve been doing this all day​:disappointed\_relieved:😥😥

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [August 30, 2023, 7:31am UTC](https://discourse.psychopy.org/t/loop-text-componet/36235/2 "2023-08-30T07:31:39Z")

</div>

> [@dawon](#):
>
> Enter $name + $sentence directly into text component  
> → Just ‘name+$sentence’ comes out in screen

The text component should contain $name + ’ ’ + sentence (only one dollar)

name = ‘’ should be in Begin Experiment not Before Experiment

Or text2 = name + ’ ’ + sentence

---

<div class="post-metadata">

**Author:** ![dawon](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@dawon](https://discourse.psychopy.org/u/dawon)\
**Post date:** [September 12, 2023, 7:17am UTC](https://discourse.psychopy.org/t/loop-text-componet/36235/3 "2023-09-12T07:17:07Z")

</div>

Thank you😊
