Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 7 years ago
Edited 7 years ago

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.

1
print(str1); print(str2); ... print(str5); prints each string on its own line BlueTaslem 18071 — 7y
0
thanks man but what i meant was i wanted to print all those strings in one V_ChampionSSR 247 — 7y

1 answer

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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.

Ad

Answer this question