So I saw the password door tutorial on the homepage (http://computercraft.info/wiki/Making_a_Password_Protected_Door) and I thought maybe I could create some kind of interface, when you place a disk drive next to the computer and then add a disk with certain information which then gets detected and executed…
But somehow I don't understand, why always when there is either no disk driver attached/ no disk inside, I get the error message:
"disk:3: Expected string"
local changecode = "-- abcdef4"
local diskPresent = 1
local enabled = true -- Sets if computer is enabled
local side = "left" -- Side of door relative to computer
local password = "password1" -- Password to enter
local opentime = 5 -- Time (sec) how long door is open
function diskSideTest()
for _, side in ipairs(rs.getSides()) do
if disk.isPresent(side) and disk.getMountPath(side) == "disk" then
return side
end
end
end
while enabled do
if disk.isPresent(diskSideTest()) and diskPresent == 0 then
print("DISK!")
sleep(2)
diskPresent = 1
if disk.hasData(diskSideTest()) then
print("DATA!")
local h = fs.open("disk/startup","r")
local changeCodeDisk = h:readLine(1)
h:close()
if changeCodeDisk == changecode then
print ("Booting from Disk")
sleep(2)
shell.run("/disk/startup")
else
print ("Disk doesn't contain correct boot-key")
end
end
else
print("What?")
sleep(2)
if not (disk.isPresent(diskSideTest())) and diskPresent == 1 then
diskPresent = 0
end
end
term.clear()
term.setCursorPos(1,1)
print("Password: ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
redstone.setOutput(side,true)
sleep(opentime)
redstone.setOutput(side,false)
else
print("Password incorrect!")
sleep(2)
end
end
And I have some questions, it would be very nice if you could help me, because I started programming with this one day ago ;)/>
- Can you have multiple "threads", for example that when you stop typing for 15 seconds, that then the program restarts?
- Is there a way to import/export programs to/from computercraft? Maybe also just documents created with notepad++ and are there also programs which can run/test them immediately, so without opening Minecraft first? (I saw, that there is somehow a way with "pastebin", but I don't understand how to use the command and I couldn't find a article in the wiki here about this) *I saw that they are saved in the saves folder for each world, but can you also access them more easily?