Table index is nil
Posted: Fri Mar 26, 2021 10:41 pm
Hi! I've been getting an error that I don't quite understand why is it happening
My goal is to make a csv file reader for some pictures that lead to other pictures, something like a gps, but I get this notification:
Error
Pictures.lua:38: table index is nil
Traceback
Pictures.lua:38: in function 'init'
class.lua:79: in function 'Pictures'
main.lua:30: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
My code is this:
local csvFile = love.filesystem.read('myCsv.csv')
local values = {}
local firstLine = true
while string.len(csvFile) > 0 do
local index = string.find(csvFile, "\n") or string.len(csvFile)
local line = string.sub(csvFile, 1, index - 1)
local lineValues = {}
for value in string.gmatch(line, "%w+") do
if firstLine then
table.insert(values, value)
else
table.insert(lineValues, value)
end
end
if not firstLine then
paths[lineValues[1] .. '.jpeg'] = {}
local size = #lineValues
for i = 2, size do
paths[lineValues[1] .. '.jpeg'][values] = lineValues[2] .. '.jpeg' (error line)
end
end
firstLine = false
csvFile = string.sub(csvFile, index + 1)
end
Can anybody help?
My goal is to make a csv file reader for some pictures that lead to other pictures, something like a gps, but I get this notification:
Error
Pictures.lua:38: table index is nil
Traceback
Pictures.lua:38: in function 'init'
class.lua:79: in function 'Pictures'
main.lua:30: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
My code is this:
local csvFile = love.filesystem.read('myCsv.csv')
local values = {}
local firstLine = true
while string.len(csvFile) > 0 do
local index = string.find(csvFile, "\n") or string.len(csvFile)
local line = string.sub(csvFile, 1, index - 1)
local lineValues = {}
for value in string.gmatch(line, "%w+") do
if firstLine then
table.insert(values, value)
else
table.insert(lineValues, value)
end
end
if not firstLine then
paths[lineValues[1] .. '.jpeg'] = {}
local size = #lineValues
for i = 2, size do
paths[lineValues[1] .. '.jpeg'][values] = lineValues[2] .. '.jpeg' (error line)
end
end
firstLine = false
csvFile = string.sub(csvFile, index + 1)
end
Can anybody help?