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

Will Computer Restart after quiting

Started by LehrLukas, 11 June 2012 - 10:12 AM
LehrLukas #1
Posted 11 June 2012 - 12:12 PM
For example, I wrote a password door. It works well. However, when I save&quit the game and come back later. The virtual computer which controls the door restarts and it's not running the program. What should I do?
The code follows:
–To prevent others from openning the door by using a redstone signal, I set the door perpendicular to the frame, instead of parallel. So it's "closed"(opened actually)when it receives a redstone signal. It will "open"(actually close) when the signal disappear.

os.pullEvent = os.pullEventRaw
password="0000"
rs.setOutput("right",true)– Keep the door "closed"
while true do
term.clear()
print "Input password"
input=read("*")
if input==password then
term.clear()
print "ID confirmed\n"
print "Input \"reset\" to reset the password\n"
print "Or input any other word to open the door\n"
cmd=io.read();
if(cmd=="reset") then
done=false
while not done do
print "Input the new password\n"
newpass=read("*")
print "Please input again to confirm\n"
confirm=read("*")
if(newpass==confirm) then
password=newpass
done=true
term.clear()
print "Password reset!\n"
else
print "The two passwords are different, please input again\n"
end
end
else

rs.setOutput("right",false)
sleep(4)
rs.setOutput("right",true)
end
else
print "Wrong password\n"
print "Access Denied\n";
end
end
Lyqyd #2
Posted 11 June 2012 - 03:57 PM
You need to add it to your startup file. For example, if your program name was passwordlock, you would add this to the startup file (with edit startup):


shell.run("passwordlock")
Bossman201 #3
Posted 12 June 2012 - 01:41 AM
I think you can also put the file on a floppy disk, put the disk in the drive next to your computer and it will work without editing any files.
LehrLukas #4
Posted 12 June 2012 - 03:48 AM
Oh, maybe it's better to use a floppy. Thank you both. If I edit startup, I have to judge the ID of the computer (I don't want every computer become a lock!)
Luanub #5
Posted 12 June 2012 - 03:54 AM
You can just create a new startup file in the root directory of the computer so that it does not affect any of the other computers. You don't have to edit the main startup file in rom, you should probably leave that one as it is.

You could also just add a check to the code that will only run the password program if the id is correct.


local id = os.computerID()

if id == 1 then
  --run password coding
end
LehrLukas #6
Posted 12 June 2012 - 05:30 AM
Wow. I did not know computers can edit their startup files respectively ! Thanks a lot
Xomsabre #7
Posted 14 June 2012 - 11:03 PM
Wow. I did not know computers can edit their startup files respectively ! Thanks a lot
Yeah, this was actually one of the first things I learned to do with CC (though the "Closed" = open and "Open" = closed thing is genius….didn't think of that before, I have to go adjust my doors and codes now xD). The simplest way to do this might be to simply enter "mv [program.name] startup" where [program.name] = your password program. This should rename the program to startup so that it runs when the computer boots.
And yes, you can change startup on each computer alone (any program you put on a computer only gets put on that computer).