local function doStuff()
do
print('hi')
if someCondition then
-- somehow exit the do scope
end
end
print('hi 2')
end
Is there a way to exit the do scope in any way without returning the function, or would I have to create another function for that? I’ve tried doing continue, break and return and all of those either cause an error, or they cause it to return the function. Any way to only exit that “do” scope and nothing else?
I probably put a bad example,
Long story short, I’m looking to make a pretty lengthy dialog which uses a custom typewriter class, and it returns a status when the typewriter is done typing. If the typewriter is stopped (through the skip button), it will return that the typewriter was abruptly stopped, if it’s abruptly stopped then it returns true. Anyway, essentially this is what my code would look like:
do
local typewriter = typewriter.new('some text')
typewriter:Play()
local status = typewriter.Stopped:Wait()
if status == true then
-- exit the scope
end
local typewriter = typewriter.new('some text part 2')
typewriter:Play()
local status = typewriter.Stopped:Wait()
if status == true then
-- exit the scope
end
end
So let’s say it was skipped at the first dialog, it would skip to the second dialog instead of exiting the scope which is what I want to do.
I did think of doing something like,
(function()
local typewriter = typewriter.new('some text')
typewriter:Play()
local status = typewriter.Stopped:Wait()
if status == true then
return
end
local typewriter = typewriter.new('some text part 2')
typewriter:Play()
local status = typewriter.Stopped:Wait()
if status == true then
return
end
end)()
however I’m not sure if it’s going to be more or less performant than just using a do-end statement.