For some reason, when I access only my main table, it's fine, but when I try to access it using a variable, it's somehow nil
?
Here's the function that's giving the error:
function parseMtl(mtlFilePath, mtlTbl) -- Parses the mtl file at mtlFIlePath
local step1 = {} -- Table to store the split lines
local mtlID = 0 -- The ID of the material
local mtlList = {} -- The list of materials
local faceColors = {} -- The returned colors of the polygons
local fC -- A test variable
contents, size = love.filesystem.read(mtlFilePath, all) -- Read the .mtl file at mtlFilePath
step1 = split(contents, "\n") -- Split the contents into step1 by the newline character
for i=1,#step1 do
if (starts(step1[i], "newmtl")) -- Create a new material
then
mtlID = mtlID + 1
mtlName = split(step1[i], "%s")[2]
table.insert(mtlList, {mtlName, mtlID})
end
if (starts(step1[i], "Kd")) -- If it's a color value, put value into the list of materials
then
R = split(step1[i], "%s")[2] * 255
G = split(step1[i], "%s")[3] * 255
B = split(step1[i], "%s")[4] * 255
table.insert(mtlList[mtlID], {R, G, B})
end
for i=1,#mtlTbl do -- Convert the mtlTbl values into 'Vertex ID, Color' format
fC = mtlList[mtlTbl[i][2]]
table.insert(faceColors, {i, fC})
end
end
return faceColors
end
The part that's doing weird stuff is the table.insert(faceColors, {i, fC})
, it's somehow returning nil
when I put fC
in a table, when I print the fC
value directly it's not nil
. I have no idea why it's doing this..