How do recursive functions work? (Sorry If it is obvious :(/> )
It would probably be better for you to make your own topic instead of posting on this one
Basically, its just a function that calls itself
function test()
test()
end
This wouldn't do anything, but a good example would
my Craft Compress program:
This is the function that actually compresses stuff
It might be a little bit complicated, but notice how it calls itself in order to keep going through directories
local function compressPath(path,iPath)
path = shell.resolve(path)
local dir = fs.list(path)
for i = 1, #dir do
if fs.isDir(path.."/"..dir[i]) then --# If the thing is a directory...
compressPath(path.."/"..dir[i],iPath.."/"..dir[i]) --# Recursive call
else --# The thing is a file, open it and 'compress' it
local tempFile = {}
table.insert(file,iPath.."/"..dir[i])
local tempFile = readFile(path.."/"..dir[i])
table.insert(file,#tempFile)
for i = 1, #tempFile do
table.insert(file,tempFile[i])
end
end
end
end