Trying to convert this to a string
customLog2 = {} Which will really look like
Log = { {Group = ID, Pos = Numbers}, {Group = ID, Pos = Numbers} }
I tried this
local Data = string.format( "LogBook = %s ", customLog2 )
But Because CustomLog is an array and not a string or a number I cant insert it. Im trying to get the array into a string for this VariableFile:write(Data) So if anyone can help that would be awesome thanks.
So I want my Output to look like this "local Data = string.format( "LogBook = %s ", customLog2 )" so I can use :write then in my newly created file it should look like this Log = { {Group = ID, Pos = Numbers}, {Group = ID, Pos = Numbers} }
So this function works expect one thing.
function TableSerialization(t, i)
local text = "{\n"
local tab = ""
for n = 1, i + 1 do --controls the indent for the current text line
tab = tab .. "\t"
end
for k,v in pairs(t) do
if type(k) == "string" then
text = text .. tab .. "['" .. k .. "'] = "
else
text = text .. tab .. "[" .. k .. "] = "
end
if type(v) == "string" then
text = text .. "'" .. v .. "',\n"
elseif type(v) == "number" then
text = text .. v .. ",\n"
elseif type(v) == "table" then
text = text .. TableSerialization(v, i + 1)
elseif type(v) == "boolean" then
if v == true then
text = text .. "true,\n"
else
text = text .. "false,\n"
end
elseif type(v) == "function" then
text = text .. v .. ",\n"
elseif v == nil then
text = text .. "nil,\n"
end
end
tab = ""
for n = 1, i do --indent for closing bracket is one less then previous text line
tab = tab .. "\t"
end
if i == 0 then
text = text .. tab .. "}\n" --the last bracket should not be followed by an comma
else
text = text .. tab .. "},\n" --all brackets with indent higher than 0 are followed by a comma
end
return text
end
My input array lets say looks like this Log = { Group = WestAPC } now this does not work because WestAPC is not a string but if WestAPC looks like this "WestAPC" it works. I need it to not be in string form.
table.concat.{ Group = WestAPC }vs{ Group = "WestAPC" }both construct a table with a single field with the same key, the string "Group". The value is set from the respective expression. In the second, the expression is a literal string. In the first, the expression is a variable. The variable's value might benil, a string, or any other type of value. In a table, if a field value is set tonil, the key-value pair is removed from the table. So, what's your goal here? Perhaps the problem is in code that you haven't shown yet.