Hello, what are your thougs about function loops?
What I mean:
function loop()
print("hi!")
wait(1)
loop()
end
loop()
Is this more efficient than while true do loops?
Hello, what are your thougs about function loops?
What I mean:
function loop()
print("hi!")
wait(1)
loop()
end
loop()
Is this more efficient than while true do loops?
Probably not. You’ll also run into a stack overflow error at some point, so using a function loop is not a good idea.
I didn’t knew it could cause a stack overflow o:
I though it could only happening when indexing and listening to __newindex
like;
Lua has a tail-call optimization, but Roblox’s Lua VM does not implement this. So, in Roblox, tail-calling recursive function is not as optimized as it could have been.
function x()
-- Yielding code
return x()
end
x()
Would normally be an optimized process, but just use a loop if you have a never-ending criteria.