This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Lupus590's profile picture

Custom Shutdown Logic

Started by Lupus590, 09 March 2015 - 08:03 AM
Lupus590 #1
Posted 09 March 2015 - 09:03 AM
I was wondering if it's possible to have custom shut-down logic (like how using puling raw events allows for custom termination).

The way I think of it would be, if there some event that gets fired when the computer shuts down (or reboots), then that could be used.

I guess my question is, is this even possible? And how could you do it?

I do have one other idea using a persistent state machine, if the state is not shut down while the program is starting then, do something.
Wojbie #2
Posted 09 March 2015 - 10:13 AM
I believe that this is on not to suggest list: here .

As for implementing something like that? You can kinda detect when player is calling shutdown or reboot by looking at keyboard input and looking for ctrl+s/r combos. But that is unreliable right now with no key_up events. In future? yea it will be possible to detect player input shutdowns and reboots. In all other cases where shutdown is caused by peripheral or program code itself it gives no warning.
Edited on 09 March 2015 - 09:17 AM
Lupus590 #3
Posted 09 March 2015 - 12:14 PM
I guess if you had an OS you could get it to queue a termination event when the player tells the OS to shutdown (via onscreen button).

One problem with watching for the keyboard inputs is:

ctrl-r detected, I now have ~3 seconds to tell everything to turn off
that is not enough time!
*several bangs and clangs from rushing*
oh dear... out of tim-


craftOS
>

I understand though, that if the OS was waiting for a program then having ctrl-r/s as a safety net for crashes is pointless
Edited on 09 March 2015 - 11:27 AM