Let's take your earlier code for example.
Option 1:
(Depth check was moved to before attempting to recursive call)
Code:
for k, v in pairs(tbl) do
if type(v) ~= 'table' then
print(v)
elseif depth > 1 then
scope(v, depth - 1)
else
print("Maximum depth reached!")
end
end
Option 2:
Code:
if depth > 0 then
for k, v in pairs(tbl) do
if type(v) ~= 'table' then
print(v)
else
scope(v, depth - 1)
end
end
else
print("Maximum depth reached!")
end