[SOLVED] Loading text string to Text Element via variable?

I have a Text Element entity that will load text on a button click via:

this.app.root.findByTag('p_Name')[0].element.text = "String of text";

To cut down on script charcters since I have dozens of buttons I thought this might do the same thing, but it doesn’t, shouldn’t it?


Variable declared:

var p_Name = this.app.root.findByTag('p_Name')[0].element.text;

Code line in a function:
p_Name = "String of text";

What did I get wrong?

Thanks!

p_Name will contain the value of what element.text is as .text returns a string (https://developer.playcanvas.com/en/api/pc.ElementComponent.html#text)

What would want is a reference to the element object:

var p_NameElement = this.app.root.findByTag('p_Name')[0].element;
p_NameElement.text = "String of text";
1 Like

That worked perfectly, thank you!