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

[Question] Modifiy a Door Lock

Started by Deadlystrike, 18 August 2012 - 03:23 PM
Deadlystrike #1
Posted 18 August 2012 - 05:23 PM
Currently i have this running on a few computers it used floppy disk as access cards.

-- Settings
side = "bottom" --location of diskdrive
pass = "4"
--PROGRAM
power(side, false)
shell.run ("clear")
print ("==========================")
print ("=Protection: Active=")
print ("==========================")
print ("ACCESS LEVEL NEEDED:"..pass)
while true do
os.pullEvent()
if disk.isPresent(side) == true then
if fs.exists("disk/level") then
file = io.open("disk/level", "r")
passt = file:read()
if passt >= pass then
shell.run ("clear")
print ("Access Granted")
disk.eject(side)
redstone.setBundledOutput("back", colors.blue)
redstone.setBundledOutput("left", colors.blue)
redstone.setBundledOutput("right", colors.blue)
sleep(4)
redstone.setBundledOutput("back", 0)
redstone.setBundledOutput("left", 0)
redstone.setBundledOutput("right", 0)
shell.run ("clear")
shell.run ("level4")
else
print ("ACCESS LEVEL NOT HIGH ENOUGH")
sleep(1)
disk.eject(side)
os.reboot()
end
end
disk.eject(side)
end
end
I would like to add the ability that when you type the word "hack" it will run a new program
The issue is by default you can type text while this program is running. I thought this would do the trick but any were i add it causes complications.

input = read()
if input == "hack" then
shell.run (hack)
I simply want it to run as it does in the code at the top and still allow text input and anytime the work hack is entered it runs that hack program.
Any help?
OmegaVest #2
Posted 18 August 2012 - 08:35 PM
Ermm. There is a lot that could use work here to make it so you can do that.

First, what the H is "level14"? If it is this program, dump the shell.run call and make the while loop cover everything that you need to. That includes clearing the screen (term.clear() term.setCursorPos(1,1)) and rewriting the interface.

Then, put event, arg1, arg2 = in front of your os.pullEvent. Make your isPresent if statement into


if event == "disk" then

Then add this if statement.


elseif event == "char" then
   input = read()
	  if input == "hack" then
		 break
	  end
   end
end



If you can follow all of that (because I don't feel like actually rewriting it for you right now), you should have a working door program that will always run, be able to check the disk, and so forth. There are a few minor things that will need following up, but this should od what you asked.
Deadlystrike #3
Posted 18 August 2012 - 09:43 PM
Ermm. There is a lot that could use work here to make it so you can do that.

First, what the H is "level14"? If it is this program, dump the shell.run call and make the while loop cover everything that you need to. That includes clearing the screen (term.clear() term.setCursorPos(1,1)) and rewriting the interface.

Then, put event, arg1, arg2 = in front of your os.pullEvent. Make your isPresent if statement into


if event == "disk" then

Then add this if statement.


elseif event == "char" then
   input = read()
	  if input == "hack" then
		 break
	  end
   end
end



If you can follow all of that (because I don't feel like actually rewriting it for you right now), you should have a working door program that will always run, be able to check the disk, and so forth. There are a few minor things that will need following up, but this should od what you asked.
sorry, i don't follow you at all. I didn't make the code originally, i just modified to to my needs. Still learning
Also "Level4" is the name of the program i put that there so it loops after a successful run
Cranium #4
Posted 19 August 2012 - 12:44 AM
Step 1: Learn Lua.
Step 2: Replace the shell.run("Level4") with os.reboot(), and just rename your door lock as "startup".
Step 3: Learn more Lua.
Step 4: Follow Omega's advice after learning a bit more. He has some good tips.
Noodle #5
Posted 19 August 2012 - 05:06 AM
Step 1: Learn Lua.
Step 2: Replace the shell.run("Level4") with os.reboot(), and just rename your door lock as "startup".
Step 3: Learn more Lua.
Step 4: Follow Omega's advice after learning a bit more. He has some good tips.
You don't need to be mean.
It looks like he knows Lua, if you actually read the code


input = read()
if input == "hack" then
shell.run (hack)
I simply want it to run as it does in the code at the top and still allow text input and anytime the work hack is entered it runs that hack program.
Any help?
It would be shell.run("hack")
Cranium #6
Posted 19 August 2012 - 05:08 AM
I wasn't trying to be mean, Just assuming since he said that he did not make the code himself, that he didn't know Lua.
Deadlystrike #7
Posted 19 August 2012 - 03:06 PM
im learning, slowly but learning none the less….
so any other help??