Display text on a text file on corona

Hey been a while.

Here’s a question…

Let’s say in my project files there is a text file named “stuff.text”

This is the following contents in the file:

“Hi I am Joey,
I like to sleep,
yeh”

If I want to display that on with corona using newText how would I do that?
I don’t want to do that manually as the file could update (let’s say it does)

Any ideas?

You load the txt file to a string and update the newText object to display that text.

To get line shift you could add “\n” in the appropriate locations in the textfile.

There are many ways to manipulate that string to display the text by for example looping through characters to get the classic RPG adventure game text type effect.

How do I load the text file into a string?

Hi JoePringles,

You could use .LUA file instead of .TXT. I think it is easier require .LUA  file than load string from file.

-- mystring.lua return "Hi I am Joey,\nI like to sleep,\nyeh" -- OR --[==[return [[ Hi I am Joey, I like to sleep, yeh]] --]==] -- test.lua local mystring = require 'mystring' print( mystring )

.JSON file also will do.

Have a nice day:)

ldurniat

It’s easily found in the documentation mate

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

Thanks a bunch! Instead of .txt files could this be done with .log files?

You load the txt file to a string and update the newText object to display that text.

To get line shift you could add “\n” in the appropriate locations in the textfile.

There are many ways to manipulate that string to display the text by for example looping through characters to get the classic RPG adventure game text type effect.

How do I load the text file into a string?

Hi JoePringles,

You could use .LUA file instead of .TXT. I think it is easier require .LUA  file than load string from file.

-- mystring.lua return "Hi I am Joey,\nI like to sleep,\nyeh" -- OR --[==[return [[ Hi I am Joey, I like to sleep, yeh]] --]==] -- test.lua local mystring = require 'mystring' print( mystring )

.JSON file also will do.

Have a nice day:)

ldurniat

It’s easily found in the documentation mate

https://docs.coronalabs.com/guide/data/readWriteFiles/index.html

Thanks a bunch! Instead of .txt files could this be done with .log files?