So I have this function but I don’t know how I can put it into a string so if someone could help me I would be greatful
Here is the function
function FancyPrint(Name, Object, Recursions)
local Padding = string.rep(" ", Recursions * 4)
if Recursions == 20 then
print(Padding.."Reached recursion limit")
return
end
local Otype = string.format("[%s]", type(Object))
Otype = string.rep(" ", 10 - #Otype) .. Otype
print(('%s> %s "%s" - %s'):format(Padding, Otype, Name, tostring((typeof(Object) == "Instance" and Object:GetFullName() or typeof(Object) == "string" and '"'..Object..'"' or Object))))
if type(Object) == "table" then
for I,V in pairs(Object) do
FancyPrint(I, V, Recursions + 1)
end
end
end
Example of what I want to be able to do
local String = FancyPrint()
The problem ios that it wont let me do taht and I do not know why
IF SOMEONE CAN HELP I WOULD BE GREATFUL
Also I want it to return things like
"A", "B", "C", 1, 2, 3
SO IF I CAN GET IT TO RETURN THAT I WOULD BE HAPPY
Here is a copy of a deep print that handles infinitely deep recursion and cycles without imposing a hard limit that I wrote a couple years ago:
local l = ' |'
local lines, cache, count
local function deepPrint(data, prefix)
if cache[data] then
lines[#lines + 1] = prefix .. '[' .. cache[data] .. ']'
return
end
count = count + 1
local name = 'table_' .. count
cache[data] = name
for key, value in next, data do
local valuet = type(value)
local keyt = type(key)
if keyt == 'table' then
lines[#lines + 1] = prefix .. '[{'
deepPrint(key, prefix .. l)
if valuet == 'table' then
lines[#lines + 1] = prefix .. '}] = {'
deepPrint(value, prefix .. l)
lines[#lines + 1] = prefix .. '};'
end
elseif valuet == 'table' then
lines[#lines + 1] = prefix .. tostring(key) .. ' = {'
deepPrint(value, prefix .. l)
lines[#lines + 1] = prefix .. '};'
elseif type(value) == 'string' then
lines[#lines + 1] = prefix .. tostring(key) .. ' = "' .. tostring(value) .. '";'
else
lines[#lines + 1] = prefix .. tostring(key) .. ' = ' .. tostring(value) .. ';'
end
end
end
local function firstCall(data)
lines, cache, count = {}, {}, 0
deepPrint(data, '')
local str = table.concat(lines, '\n')
lines, cache, count = nil, nil, nil
return str
end
return firstCall
This works as a module and the returned function will stringify any value.
I should add that you should pass this to print() if you want to see the string