What do you want to achieve?
I want to get each line of a script’s source.
What is the issue?
I do not know how to split/seperate lines in a string.
What solutions have you tried so far?
I tried using split, but I cant split a return (enter)
local target = workspace.HelloScript
local lines = target.Source
local LINES = {}
LINES = lines:split("")
print(LINES)
this is the script im using, as I said I dont know how to split each line
function test()
print("this is a test")
end
this is the script I want to get the source/seperate lines from
2 Likes
kalabgs
(FartFella)
June 26, 2022, 9:16am
#2
local lines = string.split(target.Source,"\n")
3 Likes
Thanks a lot!
I have a question, what does the “/n” thing do specifically?
2 Likes
kalabgs
(FartFella)
June 26, 2022, 9:23am
#4
the “\n” is a string pattern for alot of languages which is a method for writing a line.
local str = "Hi \nHi on new line" -- prints
--[[
Hi
Hi on new line
--]]
1 Like
Oh thats interesting. Thanks for the info!
2 Likes
It’s not a string pattern, it’s an escape sequence.
Lua supports most of the common ones.
\a
bell
\b
backspace
\f
form feed
\n
newline
\r
carriage return
\t
tab
\v
vertical tab
\\
backslash
\'
single quote
\"
double quote
\113
ascii code 113
Also, you can use a backslash to allow multiline strings. I believe this is also an escape sequence.
local str = "line 1\
line 2"
2 Likes