Display text in TextBox later

Hi there,

I have been able to set up a textbox to save the user input text out into text files and/or variables, but I haven’t quite figured out how to display that saved text again later on, preferably back in the textBox or elsewhere. The user enters information that should be there whenever they return to the scene and it would be nice if it was still editable (but I can work around that if need be). Any tips?

Hi @otterslidestudio,

I think the “.text” property is the answer for this. Just use it to set the contents of the text box, based on whatever variable you’ve saved that text to.

https://docs.coronalabs.com/api/type/TextBox/text.html

Hope this helps,

Brent

Thanks Brent. That works fine if I am supplying the text, but what’s not clicking for me is how to pull the user generated  text from a file or a variable?

Hi @otterslidestudio,

Do you store the user-generated text to a variable? If so, just use that variable as the setting for the “.text” property like so:

[lua]

local sampleTextBox =  – Create the textBox in whatever way you’re already doing it

local savedText = “”

– Sometime later, save the user-generated text to the variable…

savedText = “User entered this text!”

– Sometime later, update the textBox text…

sampleTextBox.text = savedText

[/lua]

That did it. Thanks again Brent. I knew it had to be something simple.

Whoops, I spoke too soon. It works perfectly in the simulator, but the saved text is not showing up on the iPad.

Hi @otterslidestudio,

At this point, I will probably need to see some code (from you). Please remember to surround it with “lua” tags for clarity:

[lua] ... [/lua]

Brent

I figured out how to deal with it. Essentially I had sampleTextBox.text = savedText in  the section that initially created and defined the Textbox. This works in the simulator but on the device it seems that I needed to have sampleTextBox.text = savedText loaded by a specific event instead, so I just added it to a list of things I call when the scene loads and that works.

Thanks again.

Hi @otterslidestudio,

I think the “.text” property is the answer for this. Just use it to set the contents of the text box, based on whatever variable you’ve saved that text to.

https://docs.coronalabs.com/api/type/TextBox/text.html

Hope this helps,

Brent

Thanks Brent. That works fine if I am supplying the text, but what’s not clicking for me is how to pull the user generated  text from a file or a variable?

Hi @otterslidestudio,

Do you store the user-generated text to a variable? If so, just use that variable as the setting for the “.text” property like so:

[lua]

local sampleTextBox =  – Create the textBox in whatever way you’re already doing it

local savedText = “”

– Sometime later, save the user-generated text to the variable…

savedText = “User entered this text!”

– Sometime later, update the textBox text…

sampleTextBox.text = savedText

[/lua]

That did it. Thanks again Brent. I knew it had to be something simple.

Whoops, I spoke too soon. It works perfectly in the simulator, but the saved text is not showing up on the iPad.

Hi @otterslidestudio,

At this point, I will probably need to see some code (from you). Please remember to surround it with “lua” tags for clarity:

[lua] ... [/lua]

Brent

I figured out how to deal with it. Essentially I had sampleTextBox.text = savedText in  the section that initially created and defined the Textbox. This works in the simulator but on the device it seems that I needed to have sampleTextBox.text = savedText loaded by a specific event instead, so I just added it to a list of things I call when the scene loads and that works.

Thanks again.