Multi-Line Strings

This is a pretty simple question. Is there a way to write multi-line strings in a script?

I have some weapon descriptions that I am storing as strings in a module script, and I’d like to be able to read them without having to scroll horizontally.

3 Likes

Yep, all you need to do is add \n to create a new line.

For example:

"Hello,\nThis is a string."

You can also use multi-line comments:

[[Hello,
this is a string]]

And ANSCI beat me to it cause of my bad internet connection lol…

18 Likes

The [[ and ]] pairs are the Lua multiline strings.

local abc = [[test
abc
123
]]
24 Likes

I’m pretty sure that you need to use \n at the end of the first line in order to add another line in a string.
Not 100% sure, though.

1 Like

Yes, \n will add a newline character to the string itself, but I just need to write long strings across multiple lines for code readability.

1 Like

Other ways to do it

local str1 = "this is"..
	" a test"

print(str1) -- this is a test

local tab = {
	"this is",
	" a test"
}

print(table.concat(tab, "")) -- this is a test
2 Likes

Ah, gotcha.

At that point it may be better to just do

local test = "testing\n\
123 123\n\
owo"
7 Likes

How do I add a non string in my case I want to add a variable that constructs a link how would I make it so it doesn’t make it the name of the variable the variable content? But I need to be able to continue going down aswell

2 Likes