This might be what you want. Create your text file manually just in case. The file is "test.txt" in the usage example below. I got an error until I created it.
Read Line Function:
--Read line function
local function readLines(sPath)
local file = sol.file.open(sPath, "r")
if file then
local tLines = {}
local sLine = file:read()
while sLine do
table.insert(tLines, sLine)
sLine = file:read()
end
file:close()
return tLines
end
return nil
end
Write Line Function:
--Write line function
local function writeLines(sPath, tLines)
local file = sol.file.open(sPath, "w")
if file then
for _, sLine in ipairs(tLines) do
file:write(sLine)
end
file:close()
end
end
Usage:
--Make a text file
local file_make_test = sol.file.open("test.txt", "w")
file_make_test:close()
local tLines = readLines("test.txt") -- Read this file
table.insert(tLines, "This is the first line!\n") -- Line 1
tLines[2] = "This is line 2!\n" -- Line 2
tLines[3] = "This is line 3!\n" -- Line 3
tLines[4] = 50 -- Line 4
table.remove(tLines, 2) -- Remove line 2
writeLines("test.txt", tLines) --Write lines to this file
print("Lines in the file: ", #tLines) --Print number of lines
--Open file. You must open the file to get the value
local tLines = readLines("test.txt") -- Read this file
--Print line 3. Line 4 will not be 50 because we removed line 2. That means line 3 will be 50.
print("Line 4 value is: "..tLines[3])