Hello, i’m currently making a datatype documentation compiler and in order to make it work i need to check if a key already exist to not accidently overwrite the old one.
The issue is, when i try to check if the key exist using a path with has more than 1 key in it
EX : Result[Name][ConInput[v]][CName]
Where Result is the compiled dictionary. Name is the datatype name. ConInput[v] is the object(Property, Constructor, Function…) category and the CName is the name of the object.
It returns : attempt to index nil with ‘new’ *new is the object name
I tried searching this error but the one that i found with the key error was due to it been a datastore.
local Input = [[
BrickColor
Constructors
BrickColor.new ( number : Numerical Index )
Constructs a BrickColor from its numerical index.
Properties
number BrickColor.Number
The unique number that identifies the BrickColor.
]]
local SectionList = {["Constructors"] = true;["Properties"] = true;["Functions"] = true;["Math Operations"] = true}
function ConvertV2(Input)
local ConInput = string.split(Input, "\n")
local Name = ConInput[1]
local Result = {[Name] = {}}
local Sections = {}
for i, v in pairs(ConInput) do
if SectionList[v] then
table.insert(Sections, #Sections + 1, i)
table.insert(Result[Name], #Sections + 1, i)
end
end
print(Sections)
for i, v in pairs(Sections) do
if ConInput[v] == "Constructors" then
for ie, e in pairs(ConInput) do
if ie > v and ie < Sections[i + 1] then
local CName = string.split(e, " ")[1]
CName = string.gsub(CName, Name..".", "")
local CDesc = ConInput[ie + 1]
local Arguments = string.match(e, "%b()")
Arguments = string.gsub(Arguments, ".", {["("]="", [")"]=""})
Arguments = string.split(Arguments, ",")
print(Arguments)
if not Result[Name][ConInput[v]][CName] then
Result[Name][ConInput[v]][CName] = {{}, {}, {CDesc}}
else
table.insert(Result[Name][ConInput[v]][CName][3], #Result[Name][ConInput[v]][CName][3] + 1, CDesc)
end
for ai, a in pairs(Arguments) do
local Split = string.split(a, ":")
print(Split)
for aai, aa in pairs(Split) do
if aa == "" then
table.remove(Split, aai)
end
end
table.insert(Result[Name][ConInput[v]][CName][1], #Result[Name][ConInput[v]][CName][1] + 1, Split[1])
table.insert(Result[Name][ConInput[v]][CName][2], #Result[Name][ConInput[v]][CName][2] + 1, Split[2])
print(Split[1].." : "..Split[2])
end
print(Result)
end
end
end
end
end
ConvertV2(Input)
```The code is pretty messy but it is not even totaly working yet so im not at he stage of optimising everything