Reading a text file with raw data (no common format)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
TheGuardian163
Prole
Posts: 2
Joined: Fri Dec 11, 2015 5:54 pm

Reading a text file with raw data (no common format)

Post by TheGuardian163 » Sat Jul 14, 2018 9:42 pm

I made a level editor in another engine that exports a .txt file with just integers in it. Then a space, then the next number is on the next line.

Like this:

NSLNSLNS

N is a number, S is a space, L is a linebreak. The files look like this:

6
2
8

I've read through this multiple times: viewtopic.php?t=81439
And this a few times as well: https://www.love2d.org/wiki/love.filesystem.read

I don't understand how to use these functions to add those values to a table. Would someone please write a code snippet that does it to help me understand how it's applied in practice?

Thank you for your help

grump
Party member
Posts: 443
Joined: Sat Jul 22, 2017 7:43 pm

Re: Reading a text file with raw data (no common format)

Post by grump » Sat Jul 14, 2018 10:26 pm

Code: Select all

local numbers = {}
for line in assert(love.filesystem.lines('filename.txt')) do
    numbers[#numbers + 1] = assert(tonumber(line))
end

Post Reply

Who is online

Users browsing this forum: Google [Bot], YoungFlyme and 6 guests