If you have 2 functions and one function inside the other, how can you return on the first one?
function a()
function b()
–return a?
end
end
I simply want to stop further execution of a.
I know there are some possible ways such as setting a variable and adding a conditional but is there a way to quickly return the first function?
How is code going to help anything? I already showed in my post what I was asking for. I dont need help with my code, I need help with general scripting functions that utilizes a return of the first function within the second function
I’m assuming you mean something like this. Yes you can if it is.
local function a()
return 4
end
local function b()
return a -- "a" holds our function, so we can call it normally
end
local functionResult = b() -- a is returned, so we can do the following:
print(functionResult()) -- should print 4!
Let’s say we have functions a and b. Function b is nested within function a, and you want function b to be able to stop execution of function a. You can return a flag from function b to determine whether or not to return within function a.
Example:
local function a(): nil
local function b(): boolean
return true;
end
if b() then
return; --This will break out of a if b returns true
end
--Other stuff
end