Quote:
But using return still had some error messages appeared.
It always helps to give the error message.
For deeply nested functions doing a return will not exit the whole script, just the function it is in.
If this is what is happening, using a protected call (pcall) will do the trick. Here is an example:
function foo (a)
if a == "stop" then
error "exit_function"
end -- some error condition
end -- foo
function bar (x)
foo (x)
end -- bar
local ok, err = pcall (bar, "stop")
if not ok then -- error
if string.match (err, "exit_function") then
return
end -- expected error
error (err, 2) -- some other error
end -- error
In this example, I am using pcall to call function bar, which then calls foo, and in foo if the argument is "stop" then it raises an error. This immediately jumps it out of all the nested functions back to the line after the pcall.
Then we test for the word "exit_function" in the error message. If we get that, we simply exit altogether. Otherwise it might be some other sort of error, so we raise the error again.
However this is more complex than you need if you are not using nested functions. Simply return from the script as David suggested:
if "%2" == "" or "%2" ~= "" then
return
end
Although in this particular case the test looks a bit strange. That condition would always be true wouldn't it?