Loading a file, and writing lines from that file to a variable?
Posted: Sun Mar 06, 2022 4:04 am
Hi, I'm coming from years of using GML, so I understand the logic, but just can't find the words for what I'm trying to do.
I have a text file that basically contains a bunch of lines like this;
15011000
16011007
01013500
01020001
13022210
14022000
05030570
01038004
all of the lines are the same length, 8 characters, and are all on their own, separate lines.
All I want to do is loop through each individual line in the file, and convert each line to a new string entry in an array, but I'm having trouble understanding how file is loaded, and how to copy just 1 line to a string. I read a lot of the manual, and came across love.filesystem.lines(), but I'm uncertain how it works. The example the documentation gave was just
Which isn't the most understandable for me. How is highscores.lst formatted? What is 'line' being used in the for loop? Is this even applicable to my situation? It seems like love.filesystem.lines() is the function I'm looking for, I just don't get how it's being used in the example situation, and how it relates to my situation.
Assuming 'line' in the example is the number of lines in the file, I feel like the solution would be something like
but I'm just not sure what '(string loaded from love.filesystem.lines())' would ACTUALLY be, if that makes sense?
I have a text file that basically contains a bunch of lines like this;
15011000
16011007
01013500
01020001
13022210
14022000
05030570
01038004
all of the lines are the same length, 8 characters, and are all on their own, separate lines.
All I want to do is loop through each individual line in the file, and convert each line to a new string entry in an array, but I'm having trouble understanding how file is loaded, and how to copy just 1 line to a string. I read a lot of the manual, and came across love.filesystem.lines(), but I'm uncertain how it works. The example the documentation gave was just
Code: Select all
local highscores = {}
for line in love.filesystem.lines("highscores.lst") do
table.insert(highscores, line)
end
Assuming 'line' in the example is the number of lines in the file, I feel like the solution would be something like
Code: Select all
for line in love.filesystem.lines(file) do
array[line] = (string loaded from love.filesystem.lines())
end