Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to do i make multiple strings spaced under each other?

I'm trying to print for example, 5 strings. I however, want each string to be printed in a seperate line:

str1="String 1"
str2="String 2"
str3="String 3"
str4="String 4"
str5="String 5"

I want to print all of those strings but instead of the output being:

String 1 String 2 String 3 String 4 String 5

I want it to be:

String 1
String 2
String 3
String 4
String 5

Thanks.

2 comments

1

print(str1); print(str2); ... print(str5); prints each string on its own line

0

thanks man but what i meant was i wanted to print all those strings in one

1 answer

Store it in a multi-line string using [[ and ]]:

a= [[Line 1
Line 2
Line 3
]]
print(a)
Line 1
Line 2
Line 3

--If you skip the first line, lua will also skip it.

a = [[
Line 1
Line 2
Line 3
]]
print(a)
Line 1
Line 2
Line 3

Tested in studio; Works as expected.

Any questions? post a comment below ;)

EDIT: Another way to do this, is to loop through your values and print them individualy, but that would probably require you to store the strings in a table.

Example:

local s1 = "string1"
local s2 = "string2"
local s3 = "string3"
local s4 = "string4"
local strings = {s1,s2,s3,s4}

for _,v in pairs(strings) do
	print(v)
end

will print

string1
string2
string3
string4

If you want any explaination on how this / a for loop works, let me know down in the comments.

This discussion is preserved as it was. New answers, comments, and votes are closed.