# Text component in Pavlovia showing properties

**URL:** <https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278>\
**Category:** Online experiments\
**Created:** [December 14, 2024, 1:21am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278 "2024-12-14T01:21:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 14, 2024, 1:21am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/1 "2024-12-14T01:21:41Z")

</div>

URL of experiment: [untitled [PsychoPy]](https://run.pavlovia.org/catemaccoll/e4version7/? __pilotToken=c4ca4238a0b923820dcc509a6f75849b&__ oauthToken=68814034c85abdf04aadde2b8c295fc484f5531b680b235b9062e66fb777eec0)

Description of the problem: Text component is being populated from a sequential loop with an excel sheet with different text, and $text as the content. Online it is showing as a full description of the text component (e.g., name = textStim, details about size, etc.) instead of the text itself

---

<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:** [December 14, 2024, 8:16am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/2 "2024-12-14T08:16:31Z")

</div>

This suggests that you are using text as the name of a text component and also a variable for the contents. Try changing one of those… probably the contents.

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 14, 2024, 10:14pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/3 "2024-12-14T22:14:23Z")

</div>

I didn’t have any components named just “text” but I did reuse “text” as the value across multiple components in separate routines. I’ve gone through and renamed them text\_4, 5, 6, etc. and also added code components to component.setText(text\_4) because they weren’t functioning without that. However, now some routines are saying that text\_30 can’t be found, even though I’ve used the exact same procedure - any thoughts?

---

<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:** [December 14, 2024, 10:23pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/4 "2024-12-14T22:23:16Z")

</div>

It’s absolutely fine to use the same variable to contain different strings (contents) at different points in the study.

However, text, text\_2, text\_3, etc are the default names for the text components so I wouldn’t recommend using them for the strings.

msg is often used for the text string.

Do you need to set the text in code components? If so, then I typically use text\_2.text = msg rather than text\_2.setText(msg). I can’t remember if there’s a reason for this.

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 14, 2024, 10:37pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/5 "2024-12-14T22:37:30Z")

</div>

I don’t need to set them in code components, I am using a loop in theory but it was still just presenting the descriptions of the components as above, unless I added a code component. I would normally just set them in builder. But now even with a code component I get the error that the contents can’t be found

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 14, 2024, 10:43pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/6 "2024-12-14T22:43:37Z")

</div>

I just updated to the “text\_2.text = msg” approach, but still get the message that “msg” can’t be found (see below). I have triple checked all naming and in the code there’s no difference to the earlier routines of when msg is called

- **ReferenceError: Can’t find variable: phase2\_instrClosed\_msg**

---

<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:** [December 14, 2024, 11:29pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/7 "2024-12-14T23:29:48Z")

</div>

> [@Cate\_MacColl](#):
>
> phase2\_instrClosed\_msg

Please could you show where you define **phase2\_instrClosed\_msg**?

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 14, 2024, 11:42pm UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/8 "2024-12-14T23:42:37Z")

</div>

In an excel spreadsheet, I’ve just made the full GitLab available if that helps? - [Cate MacColl / E4version7 · GitLab](https://gitlab.pavlovia.org/catemaccoll/e4version7.git)

---

<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:** [December 15, 2024, 8:39am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/9 "2024-12-15T08:39:20Z")

</div>

It’s still private. You could just upload your psyexp file here.

If you don’t need to set the values in code components then don’t. I sometimes use code components if there are functions used when building the text that need to be translated to JS.

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 8:17am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/10 "2024-12-16T08:17:33Z")

</div>

Apologies - I’ve attached the .psyexp here. I wouldn’t usually specify them in code, but it didn’t work unless I added the code component. There is now a problem in the experiment itself where it is not accurately calling from a spreadsheet to set the response option (which seems like the same problem - it’s just not reading from spreadsheets in the loops when I upload it to Pavlovia)

[E4version8.psyexp](https://discourse.psychopy.org/uploads/short-url/cn7WluQYc0SBIi2iyALecTBIVVG.psyexp) (409.7 KB)

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 8:55am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/11 "2024-12-16T08:55:46Z")

</div>

In this case in phase2 I set images to either box1, box2, box3 or box4 with an inner loop that sets these values to colourA or colourB, and then an outer loop that sets colourA and colourB to either “red.png” or “blue.png” for counterbalancing purposes. I’ve tried in the inner loop specifying directly to red and blue.pngs and that works, and I’ve put a test trial inside the outer loop (but outside the inner) that sets an image to colourA, and that works too. It is something about the double loop that seems to not be working

---

<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:** [December 16, 2024, 9:59am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/12 "2024-12-16T09:59:16Z")

</div>

I recommend moving code components to the tops of their routines.

If you have Begin Routine code, it can’t affect a component above it.

However, I would start by removing all the code that’s duplicating the components being set each repeat.

You could make your code more efficient by reusing routines. For example, Are randInstr and phase2Closed the same? If you changed text\_17 in E4\_randinstr.xlsx to msg then you could use phase2Closed.

However, I would also change image.

**Use simple terms for variables, since they may already be in use by PsychoPy. Variable names to avoid are: class, core, final, image, index, Length, list, Object, Number, round, sound, Symbol, t, thisTrial, trials, util, visual.**

> **[PsychoPy Python to Javascript crib sheet 2023](https://docs.google.com/document/d/1TSEgiG3SeGSr7LWoRahTZm7vk_loU8zKoDQh2sV1KFw/edit?tab=t.0#heading=h.9aaotovh825k)**
>
> PsychoPy version 2023.1.3Python to JavaScript Crib Sheet Compiled by Wakefield Morys-Carter, Oxford Brookes UniversityPlease share widely and follow Psych\_Stats on twitter. There have been significant improvements in the auto translation function in...

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 10:12am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/13 "2024-12-16T10:12:57Z")

</div>

Hi Wakefield, I have created a new file to replicate the problem of my Pavlovia experiment not reading excel in loops, and can’t identify why this isn’t working. The inner loop works in isolation, and the outer loop can independently specify images, but the combination of both results in a “resource unknown” error. I haven’t added any code components.

 ![box_red](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/e/2ee9e2660ef5939d23796a53b86b78d29bad49bf.png)  
 ![box_blue](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/2/7/27eb84ada574d08c4b9dd4b1afa4053980596826.png)  
[testOuterLoop.xlsx](https://discourse.psychopy.org/uploads/short-url/7eF6Hf4nJeppJm9kH6zHDi1l83q.xlsx) (8.7 KB)  
[testInnerLoop.xlsx](https://discourse.psychopy.org/uploads/short-url/t5uv7m5XZQf0IiSZZHP2c0bkRX6.xlsx) (8.7 KB)  
[replication.psyexp](https://discourse.psychopy.org/uploads/short-url/zuCkalu6UL0uzjj7KGYkTNjwSXM.psyexp) (13.9 KB)

---

<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:** [December 16, 2024, 10:19am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/14 "2024-12-16T10:19:59Z")

</div>

Maybe in concentric loops you need top specify the resources in Experiment Settings / Online / Additional resources.

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 10:23am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/15 "2024-12-16T10:23:34Z")

</div>

Unfortunately, I’ve tried adding them in additional resources as well as changing back to an older version of PsychoPy, see error attached. I’ve deleted and reuploaded them, and made sure to create all the excel sheets from scratch.

 ![Screenshot 2024-12-16 at 8.21.42 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/7/c/7c441904eb31c28eea8d184d426a460db53af6b2.png)

---

<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:** [December 16, 2024, 10:32am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/16 "2024-12-16T10:32:26Z")

</div>

Check in an incognito tab.

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 10:33am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/17 "2024-12-16T10:33:47Z")

</div>

Same problem

---

<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:** [December 16, 2024, 10:40am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/18 "2024-12-16T10:40:46Z")

</div>

The problem is that when you set the image as $testImage you are setting it as either “colourA” or “colourB” as strings not as variables.

Here’s some code:

```auto
if testImage == 'colourA':
    thisImage = colourA
else:    
    thisImage = colourB

```

In the attached psyexp file I also move the code component to the top and added thisImage = ‘’ in Begin Experiment as well as setting the image to present $thisImage

[replication.psyexp](https://discourse.psychopy.org/uploads/short-url/vcaGATHnGC87Qro7wmuDhiyzlyM.psyexp) (14.2 KB)

---

<div class="post-metadata">

**Author:** ![Cate\_MacColl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/cate_maccoll/32/35315_2.png) [@Cate\_MacColl](https://discourse.psychopy.org/u/Cate_MacColl)\
**Post date:** [December 16, 2024, 11:01am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/19 "2024-12-16T11:01:08Z")

</div>

That’s fantastic - thank you! Is it surprising that it’s reading as a string? I’ve used this approach in previous versions of PsychoPy without a problem…

Would the problem with text components be related if they are also in a concentric loop, or should they be fine with a string?

---

<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:** [December 16, 2024, 11:21am UTC](https://discourse.psychopy.org/t/text-component-in-pavlovia-showing-properties/43278/20 "2024-12-16T11:21:21Z")

</div>

I don’t know if your approach used to work in earlier versions, but there have been variations over the years on how lists, for example, get read from spreadsheets. I suspect that the concentric loop issue is because that’s when you started using the inner loop to refer to a column in the outer loop.
