Jump to content




Stop Terminating And Custom Terminating


  • You cannot reply to this topic
4 replies to this topic

#1 jay5476

  • Members
  • 289 posts

Posted 09 October 2013 - 03: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
os.pullEvent = os.pullEventRaw
now for an explaination
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:
Spoiler
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
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 so

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)

#2 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 09 October 2013 - 11:51 AM

Hmm, what uses would this have?

#3 jay5476

  • Members
  • 289 posts

Posted 09 October 2013 - 03:49 PM

custom terminate? well you could log a terminate or give a notification to the person

#4 AgentE382

  • Members
  • 119 posts

Posted 09 October 2013 - 06:06 PM

Save state on user intervention.

For example, I'm working on a program that maintains a mapping of files to a certain type of ID, saving the database to disk after every session and loading it before the next session. Normal users can call my program from the command-line, which is no problem. Each call is a single session. But, developers can also load it as an API, for use in their own programs.

I could use something like this to safeguard developers from noob users who will whine about the other developers' programs losing their data after they press Control-T.

#5 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 October 2013 - 04:41 PM

I have a screensaver that only resets with Ctrl + T (yeah, I'm a noob), so it would be a nice thing to do to reset the monitor to default colours on exit.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users