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

Startup/shutdown

Started by Duster, 21 March 2016 - 09:06 PM
Duster #1
Posted 21 March 2016 - 10:06 PM
I know there is a startup script, soo is there a shutdown one?
Lupus590 #2
Posted 21 March 2016 - 10:15 PM
nope, you could override os.shutdown for your custom shutdown needs though


local oldShutdown = os.shutdown --# make a backup of the old function
function os.shutdown()
  --# add your custom shyutdown here

  oldShutdown() --#this is why we needed the backup
end
Edited on 21 March 2016 - 09:16 PM
Bomb Bloke #3
Posted 21 March 2016 - 10:17 PM
Of course, that'll only trigger if you specifically run a script that calls that doctored function. If the server shuts down or the computer's chunk unloads, the system will still simply shut off without running any special code.
Duster #4
Posted 21 March 2016 - 10:28 PM
so there is no script that fires before the computer shuts down
Edited on 21 March 2016 - 09:29 PM
Duster #5
Posted 21 March 2016 - 10:39 PM
Edit: is there a way to turn off a computer on a lan network?
Duster #6
Posted 21 March 2016 - 10:53 PM
Of course, that'll only trigger if you specifically run a script that calls that doctored function. If the server shuts down or the computer's chunk unloads, the system will still simply shut off without running any special code.
nope, you could override os.shutdown for your custom shutdown needs though


local oldShutdown = os.shutdown --# make a backup of the old function
function os.shutdown()
  --# add your custom shyutdown here

  oldShutdown() --#this is why we needed the backup
end

anyway to turn off computers on a lan network
Anavrins #7
Posted 21 March 2016 - 11:32 PM
anyway to turn off computers on a lan network
Yes, peripheral.find("computer").shutdown()
Although, this will not run os.shutdown(), so it can't be overriden.
Edited on 21 March 2016 - 10:33 PM
Duster #8
Posted 21 March 2016 - 11:34 PM
what do you mean it doesnt run os.shutdown?
anyway to turn off computers on a lan network
Yes, peripheral.find("computer").shutdown()
Although, this will not run os.shutdown(), so it can't be overriden.
Creator #9
Posted 21 March 2016 - 11:41 PM
anyway to turn off computers on a lan network
Yes, peripheral.find("computer").shutdown()
Although, this will not run os.shutdown(), so it can't be overriden.

Doesn't this return an address (or side)?

peripheral.call(peripheral.find("computer"), "shutdown")
Duster #10
Posted 21 March 2016 - 11:46 PM

peripheral.wrap("computer").shutdown()
Shuts down wrapped computer


anyway to turn off computers on a lan network
Yes, peripheral.find("computer").shutdown()
Although, this will not run os.shutdown(), so it can't be overriden.

Doesn't this return an address (or side)?

peripheral.call(peripheral.find("computer"), "shutdown")
Lyqyd #11
Posted 22 March 2016 - 12:50 AM
Moved to Ask a Pro.
Bomb Bloke #12
Posted 22 March 2016 - 03:06 AM
Doesn't this return an address (or side)?

peripheral.find() returns wrapped peripherals, not strings.

It is possible to do stuff with the "side name" using its optional "function" parameter, though.

Another trick is that you can use that function to perform actions through all found peripherals. For example, if you wanted to shutdown ALL computers detected on the network, you'd do:

peripheral.find("computer", function(side, object) object.turnOff() end)
Lupus590 #13
Posted 22 March 2016 - 10:09 AM
If you want to do your custom shutdown over lan then you will need something on every computer which listens for a rednet signal and then calls your custom shutdown.

your master computer then just sends the correct rednet signal to all of the computers
Duster #14
Posted 22 March 2016 - 08:33 PM
Ok ill try

If you want to do your custom shutdown over lan then you will need something on every computer which listens for a rednet signal and then calls your custom shutdown.

your master computer then just sends the correct rednet signal to all of the computers