The forum on this site is closed for new comments and posts. Continue the conversation in the new forum, and learn more here.

Change text programmatically

  • Are there any errors? This is definitely possible. Seeing your code may help and is the text using dynamic text on the component?

    Comment actions Permalink
  • I spent an hour debugging it and ended up creating 12 text objects one for each text I had to show and just hiding/showing the ones I needed instead of dynamically changing the text. Do I have to set any special property on the text object for it to work?

    Comment actions Permalink
  • I’m on my phone but I probably just do like
    Var textObject = scene.getChild(0);
    textObject.text = “my text”;

    //but the below hides it
    textObject.enabled = false;

    Comment actions Permalink
  • the property is .text, I'm guessing you are only getting the scene object though based on the code, not the actual text component of the scene object.

    Easiest way is to specifically import the component in your script like:

    //@input Component.Text myText

    then access it with script.myText

    so it would be script.myText.text = "new text"

    ---
    or use .getComponent("Component.Text") off of that scene object instead of specifcally importing a text component directly.

    Comment actions Permalink
  • thanks I'll give it a try

    Comment actions Permalink
  • How did it go Marco?

    Keep us updated so we know if Brandon's response solved your issue or not :)

    Comment actions Permalink
  • Thanks guys I'll let you know once I try. Been traveling.

    Comment actions Permalink
  • Hey guys,

     

     In both cases I got:

     

    13:43:46 [Scenarium] TypeError: cannot write property 'text' of null
    at [anon] (Script.js:8) preventsyield

     

     Any ideas why?

     

    thanks

     

     

    the script is added to the Forehead object

    Comment actions Permalink
  • I was able to make it work now like this

     

     

    var sceneObj = script.getSceneObject();

    var textObjt = sceneObj.getChild(0).getComponent("Component.Text")

     

    textObjt.text = "new text"

     

    Comment actions Permalink
  • I was also able now to do 

     

    //@input Component.Text myText

    script.myText.text = "new text"

     

     

    by linking the script text component.

     

    I think the documentation should be more clear on the steps to make this work...

    Comment actions Permalink
  • So I'm able to make this work but it only works once... I have it so when you tap the screen the text updates....   it works on first tap.. but second tap gets the following error.

     

    22:21:42 [Scenarium] TypeError: cannot write property 'text' of undefined

    Comment actions Permalink
  • What Jonathon Pitman mentions above seems to be a bug. The first time I tried it, I got the following error. To avoid this error, I rewrote the same line again, and it went away. I'm not sure what creates this error to pop.  


    Comment actions Permalink

We're here to help! We just need a little bit of information...

What system are you using?

Have you downloaded the latest version of Lens Studio?

Please download the latest version of Lens Studio. If you still run into this issue, please come back and report it!

Is this issue causing Lens Studio to crash?

What system do you run Lens Studio on?

Version

Graphics

Follow the next steps to help us solve your issue:

  • Copy and paste this text into your TerminalCommand Window
    open ~/Library/Preferences/Snap/Lens\ Studio/ %LOCALAPPDATA%\Snap\Lens Studio Copy Text
  • Press ReturnEnter to run the command. The Lens Studio folder will automatically open
  • Prepare to upload your files: zip the "Log" Folder by right-clicking and choosing "compress."
    Locate the Log.txt file right above it.

    Attach a screenshot of the issue:

Name:

Email:

What is this most relevant to?

Please enter a brief description of your issue:

Thanks for submitting this issue.

Unfortunately, it's likely due to the operating system or hardware you're using – since they don't meet the system requirements for Lens Studio.

Still, we hear you loud and clear, and are logging the issue in case there's ever a workaround we can provide!

Minimum Requirements

Operating System: Windows 10 (64 bit); MacOS 10.11+

Hardware: Minimum of Intel Core i3 2.5Ghz or AMD Phenom II 2.6Ghz with 4 GB RAM; Intel HD Graphics 4000 / Nvidia GeForce 710 / AMD Radeon HD 6450 or better; screen resolution of 1280x768 or higher

We'll try to resolve this issue as soon as possible. Thanks for letting us know about it!

Keep an eye out for a followup email from us. We may have a couple more questions for you, or we might already have a solution to offer.

Happy creating!