Posted 26 April 2012 - 01:18 AM
I have a question. Is there a way to stop a program within itself, without CTRL + T? I want a program to be able to terminate itself when the user types a specific command.
if a == 1 then
error()
end
if a == 1 then
return
end
while true do
-- program code --
if <condition to stop the program> then
break
end
end
This way works for simple programs, wich has most of it's code in a loop. It would also work changing the break with a return.
local bExit = false
while not bExit do
-- program code --
end
This is the one I use, it runs the program until you change the variable "bExit", wich can be changed anywhere in the program, so you can do it in the loop itself or make a function that changes it:
local function exit()
bExit = true
end
You have several conditions to end the program this way.