File values to array?

I have a text file called levels that I added to my project In the file I have values that tell the engine the type of piece, x,y, etc. all space delimited
Each line could be a different size based on the number of pieces. How can I turn the lines into arrays?

Sample:
0 1 0 240 210 1 1 0 285 150 1 1 0 198 150
0 1 0 300 510 0 1 0 180 510 1 1 0 300 450 1 1 0 180 450 1 3 0 240 390

Your help is greatly appreciated.

You can try something like this:

local values = {}
for v in s:gmatch("%S+") do
   table.insert(values, tonumber(v))
end

This will split a line on spaces and convert string values to numbers.

4 Likes