Posted 09 October 2013 - 04:35 AM
Hi this tutorial is supposed to help you learn how to stop terminating and create a custom terminate.
Note: there is no way to stop Ctrl+S or Ctrl+R
Stop Terminating
well stopping someone from terminating your program can be really useful and the fact that you only need this line to do it makes it better
The way ComputerCraft handles terminates is if Ctrl+T is held for 1 second(correct me if im wrong) it will send a 'terminate' event
now os.pullEvent acts on this event and then terminates. how it terminates:
and by doing that line of code it overrides os.pullEvent (which handles terminates) with os.pullEventRaw which doesn't check for the terminate event, basically os.pullEvent was built in to check for terminate and os.pullEventRaw wasn't even though they provide same functionality
Custom Terminates
well this is different you have to code os.pullEvent to handle the terminate how you want so the way I like to do it is
we want to override os.pullEvent to handle the terminate how we want so we could do something like this
I hope this tutorial helped and provided the information you needed if it didn't please leave a comment
be sure to also leave some feedback (good or bad I don't mind)
Note: there is no way to stop Ctrl+S or Ctrl+R
Stop Terminating
well stopping someone from terminating your program can be really useful and the fact that you only need this line to do it makes it better
os.pullEvent = os.pullEventRaw
now for an explainationThe way ComputerCraft handles terminates is if Ctrl+T is held for 1 second(correct me if im wrong) it will send a 'terminate' event
now os.pullEvent acts on this event and then terminates. how it terminates:
Spoiler
os.pullEvent handles terminates like this
error("Terminated",0)
which will stop the exit the program and causes red(advanced) or white text 'terminated' to appear after exitingCustom Terminates
well this is different you have to code os.pullEvent to handle the terminate how you want so the way I like to do it is
we want to override os.pullEvent to handle the terminate how we want so we could do something like this
os.pullEvent = function( _sFilter )
eventData = {os.pullEventRaw( _sFilter } -- os.pullEventRaw will give us the raw event data and store it in this table
if eventData[1] == "terminate" then -- identify the event and see if its terminate
programName = shell.getRunningProgram()
error("User has terminated the program: "..programName,0)
-- this example changes it to say the text between the quotes and then the name of the program
-- change the code after the 'if' to do whatever you want with the terminate even if its nothing
end
end
now basically this code above can be changed to handle your events however you want as long as you code it to do soI hope this tutorial helped and provided the information you needed if it didn't please leave a comment
be sure to also leave some feedback (good or bad I don't mind)