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

Return to startup upon exit.

Started by KenJ1989, 26 July 2013 - 10:16 AM
KenJ1989 #1
Posted 26 July 2013 - 12:16 PM
Titles: Return to startup upon exit.

I'm trying to make it so when I leave a computer, it will leave it's current program, (shell), and return to startup when I access the computer again.

It's probably something easy, but I have tried everything so far and have come up with nothing.
Lyqyd #2
Posted 26 July 2013 - 12:46 PM
Split into new topic.

Just hold Ctrl-R for a moment when you leave it or come back. There are other options, like a pressure plate giving it a redstone signal that it will listen for and reboot, but that's slightly more complicated to set up.
KenJ1989 #3
Posted 26 July 2013 - 12:56 PM
The computer I am using has 2 programs it runs. 1st is the startup shell, which a user enters a PW to which then leads to another shell. That shell is then used to control an area (high security, lol).

Only a couple friends and I will know the PW needed to get on, but if one of us forgets to do CRTL+R or type EXIT to exit the program, then another user can get on it and activate w/e I have the computer setup for..

So what I am getting at is, how can I have it auto re-boot as I press ESC?
Lyqyd #4
Posted 26 July 2013 - 01:15 PM
You can't. The computer can't pick up the Esc key press. You have to use an external redstone signal or similar (proximity detector with OCS, etc.) to detect when a player walks away and reset it based on that.
ZagKalidor #5
Posted 26 July 2013 - 01:22 PM
What about loading the first shell when a given time runs out. Or doing just a shut down when you leave the second shell unused for a while like a screensaver would start running. Isn't the startup program run first, after a shutdown is done?
KenJ1989 #6
Posted 26 July 2013 - 01:26 PM
You can't. The computer can't pick up the Esc key press. You have to use an external redstone signal or similar (proximity detector with OCS, etc.) to detect when a player walks away and reset it based on that.

Ah, me finding nothing makes sense now. Thanks.

What about loading the first shell when a given time runs out. Or doing just a shut down when you leave the second shell unused for a while like a screensaver would start running.

Hmm, that sounds pretty interesting. How would I code that? It'd be set like if someone was AFK for 30 seconds, that computer would reboot or something.
ZagKalidor #7
Posted 26 July 2013 - 01:35 PM
You will just start a timer, maybe everytime you are in your second shells main menue. Having this timer running out will load the first password shell. Maybe you could also auto-return to the main menue, with a timer, if some alzheimer user, doing his high security, area 51 safety access, forgets leaving it. Going back to the main menue will also activate the secret "punch in users face" function…
ZagKalidor #8
Posted 26 July 2013 - 01:39 PM
But i think Lyqyds pressure plate idea is a very good one for that purpose. Very easy - redstone is off - load first shell…

This idea would shut your prog in the moment you leave the plate. With my idea it would probably leave the computer functio al some seconds or maybe minutes, after you leave the terminal undetected.
KenJ1989 #9
Posted 26 July 2013 - 01:43 PM
But i think Lyqyds pressure plate idea is a very good one for that purpose. Very easy - redstone is off - load first shell…

This idea would shut your prog in the moment you leave the plate. With my idea it would probably leave the computer functio al some seconds or maybe minutes, after you leave the terminal undetected.

Yeah, maybe so. I'm still new to the coding thing though. :/
ZagKalidor #10
Posted 26 July 2013 - 01:48 PM
Lyqyds second idea would be much greater for that because the ocs proximity sensor would detect the players name coming up to the terminal and would grant access to the second shell without the need of a password. This would be like a fingerprint because no one else has the same username.

We all where new to that. Just feel free to ask.
KenJ1989 #11
Posted 26 July 2013 - 01:52 PM
I'm kinda liking the idea of using the pressure plate to shutdown the computer once a user steps off it. What coding would I need to do so?
Dlcruz129 #12
Posted 26 July 2013 - 01:59 PM
I'm kinda liking the idea of using the pressure plate to shutdown the computer once a user steps off it. What coding would I need to do so?

Just wait for a redstone event and then call os.shutdown().
ZagKalidor #13
Posted 26 July 2013 - 02:14 PM
If your a friend of gettin on with computercraft coding, make all 3 ideas possible. Look to it like a challenge. Btw. If your in ocs and getting it work for you, your options get nearly limitless…
KenJ1989 #14
Posted 26 July 2013 - 02:35 PM
If your a friend of gettin on with computercraft coding, make all 3 ideas possible. Look to it like a challenge. Btw. If your in ocs and getting it work for you, your options get nearly limitless…

I'm still having a hard time at getting the pressure plate to work.. lol.

IDK if it's even possible because of how I have things set up…

Behind the computer is a wireless redstone block, which controls a door. The computer controls that block/door. It front of it is a block, which I can add a pressure plate, but I can't put a redstone torch under it due to there being a room under that block.
ZagKalidor #15
Posted 26 July 2013 - 02:48 PM
Place your pressure plate in front of the computer, it will fire the front side. Or you place your computer onto a stone block. Now the pressure plate fires the stone block and the stone block fires the computers bottom side.

If rs.getInput("side you fire") ==false then shell.reboot end

If my syntax is right, sitting in the evening sun, with 5 beers as input data…

Greeeeetz :)/>/>/>/>

Edit: ah you dont need a torch for a pressure plate. New with minecraft too? Dont matter youre welcome
KenJ1989 #16
Posted 26 July 2013 - 04:43 PM
I can't get it to work that way… my computer is sitting on top of another block and the pressure plate is in front of the block it's sitting on… :/

*EDIT*
I got it to slightly work, but it doesn't shutdown when I leave the pressure plate. It only shuts down if I'm not on it after I enter my password, then it goes to the shell, then it checks if I'm on it or not.
ZagKalidor #17
Posted 27 July 2013 - 04:35 AM
Please excuse me.

After the 5th beer i wrote if ……. == true ……
Later i saw that mistake and edited it to == false

Of course, the condition must be false to shutdown your terminal when leaving the plate. I think you coded that before i corrected that mistake of mine… when the power goes off - the terminal goes off too.

Sorry for that pal.

But one condition always stays true: dont code when youre drunk!!!

I had some beers on every coder of the ocs mod yesterday and 3 or 4 on Lyqyd. So my functions went slowly but steady to return nil.
Coding error: braincell 1264378: syntax wrong me nerd
albrat #18
Posted 27 July 2013 - 04:53 AM
Do you have a main loop around your private shell program ? if so, how often does it loop ?

If it loops often then we could change the while true do to while rs.getInput("side") do – where == true is the default value and is not needed.

so when your redstone is turned off… the program exits the loop and runs your reset commands. eg. os.shutdown() – which just shuts down the os.

But you put your shutdown commands outside your main program loop after the redstone turns off it will run the shutdown.


while rs.getInput("front") do
	 -- program stuffs
end -- end of main loop
os.shutdown()  -- will only run if the main loop exits.
-- //EOF
KenJ1989 #19
Posted 27 July 2013 - 04:28 PM
Do you have a main loop around your private shell program ? if so, how often does it loop ?

If it loops often then we could change the while true do to while rs.getInput("side") do – where == true is the default value and is not needed.

so when your redstone is turned off… the program exits the loop and runs your reset commands. eg. os.shutdown() – which just shuts down the os.

But you put your shutdown commands outside your main program loop after the redstone turns off it will run the shutdown.


while rs.getInput("front") do
	 -- program stuffs
end -- end of main loop
os.shutdown()  -- will only run if the main loop exits.
-- //EOF

I'm new to coding on Minecraft so I don't know what you just said.. lol.
ZagKalidor #20
Posted 29 July 2013 - 12:12 PM
You might loop your mainfunctions, as long as the pressure plate is on and break all operations, when its turned off…
albrat #21
Posted 29 July 2013 - 06:45 PM
can you post a copy of your program code please, I could change the way it works to show you as an example i hope. :)/>

My idea is to create a loop that exits when you step off the pressure plate. like an instant off button, no redstone signal.. The computer shuts down.

for example a function like this…

function testRed()
  if not rs.getInput("front") then
    os.shutdown()
  end
end


This function would need to be added to your code, then you could just add a function call in your program… after each input etc… and it would check for the pressure plate. If the pressure plate fails the computer shuts down. os.pullEvent() – you would need to add a timer event so these trigger the check on the redstone signal.

With your code I could add these changes to show you how it would work.