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

Ok, so I've got this program...

Started by MistahEpic, 21 April 2013 - 08:14 PM
MistahEpic #1
Posted 21 April 2013 - 10:14 PM
Ok, so I've got this nice little program I've been working on for a code door…


os.pullEvent = os.pullEventRaw
local password = "0182"

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
print("Access Granted")
rs.setOutput("left",true)
sleep(4)
rs.setOutput("left",false)
os.reboot()
else
print("Access Denied")
sleep(3)
os.shutdown
end

and I want to make it so that when someone enters a certain code (specifically "2810") it disables the "os.pullEvent = os.pullEventRaw" so that it can still be edited. so, if anyone knows of a way to make it happen, please respond. and it would be nice if you would explain it, aswell. i like to know what im typing. thanks :)/>
Cranium #2
Posted 21 April 2013 - 10:25 PM
Moved to the Ask a Pro section.
BigSHinyToys #3
Posted 21 April 2013 - 10:26 PM
For future reference all questions should be directed to the Ask a Pro section.


local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "0182"
local specialPassowrd = "2810" -- other password

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
    print("Access Granted")
    rs.setOutput("left",true)
    sleep(4)
    rs.setOutput("left",false)
    os.reboot()
elseif input == specialPassowrd then -- if input not same as passowrd then if input same as special password
    print("Disableing Ctrl + T protect")
    os.pullEvent = oldPullEvent -- restore os.pullEvent
else -- if input not same as password ans special password then do this
    print("Access Denied")
    sleep(3)
    os.shutdown()
end
MistahEpic #4
Posted 21 April 2013 - 10:40 PM
For future reference all questions should be directed to the Ask a Pro section.


local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "0182"
local specialPassowrd = "2810" -- other password

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
	print("Access Granted")
	rs.setOutput("left",true)
	sleep(4)
	rs.setOutput("left",false)
	os.reboot()
elseif input == specialPassowrd then -- if input not same as passowrd then if input same as special password
	print("Disableing Ctrl + T protect")
	os.pullEvent = oldPullEvent -- restore os.pullEvent
else -- if input not same as password ans special password then do this
	print("Access Denied")
	sleep(3)
	os.shutdown()
end



Thanks a lot. I'll be sure to post to ask a pro next time.
MistahEpic #5
Posted 22 April 2013 - 12:12 AM
For future reference all questions should be directed to the Ask a Pro section.


local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "0182"
local specialPassowrd = "2810" -- other password

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
	print("Access Granted")
	rs.setOutput("left",true)
	sleep(4)
	rs.setOutput("left",false)
	os.reboot()
elseif input == specialPassowrd then -- if input not same as passowrd then if input same as special password
	print("Disableing Ctrl + T protect")
	os.pullEvent = oldPullEvent -- restore os.pullEvent
else -- if input not same as password ans special password then do this
	print("Access Denied")
	sleep(3)
	os.shutdown()
end




uh oh, there appears to be another problem.



local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "0182"
local engineer = "2810"

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
    print("")
    print("Access Granted")
    rs.setOutput("left",true)
    sleep(4)
    rs.setOutput("left",false)
    os.shutdown()
elseif input == engineer then
    print("")
    print("Engineer Status Confirmed")
    term.write("Unlocking")
    textutils.slowPrint("...")
    sleep(2)
    term.clear
    term.setCursorPos(1,1)
    os.pullEvent = oldPullEvent
else
    print("")
    print("Access Denied")
    sleep(3)
    os.shutdown()
end

in case it wasnt obvious, i change a few names and added a few extra lines to make it look more neat. this is the error i get when i try to run it: bios:338: [string "startup"]:27: '=' expected

ive tried everything i can think of to fix it. i am assuming that 27 is a line number, so i removed the line and got the same error. line 27 is " term.setCursorPos(1,1)"

and while im getting your attention, you wouldnt happen to know how to exactly copy and paste a program from say, notepad into the computer, would you? whenever i try ctrl v it adds part of the first line i was trying to paste and saves it

thanks in advance
theoriginalbit #6
Posted 22 April 2013 - 12:19 AM
in your elseif input == engineer you are missing the () on term.clear
MistahEpic #7
Posted 22 April 2013 - 12:24 AM
in your elseif input == engineer you are missing the () on term.clear

that did it! thanks. the littlest mistake, amiright?
MistahEpic #8
Posted 22 April 2013 - 12:52 AM
in your elseif input == engineer you are missing the () on term.clear

weird, for some reason whenever i enter my engineer code it still shuts down. exact copy from computer file:



local oldPellEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "0182"
local engineer = "2810"

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
print("")
print("Access Granted")
rs.setOutput("left",true)
sleep(4)
rs.setOutput("left",false)
os.shutdown()
elseif input == engineer then
print("")
print("Engineer Status Confirmed")
sleep(3)
term.clear()
term.setCursorPos(1,1)
os.pullEvent = oldPullEvent
else
print("")
print("Access Denied")
sleep(3)
os.shutdown()
end

any ideas? thanks in advance
BigSHinyToys #9
Posted 22 April 2013 - 02:00 AM
line 1 local oldPellEvent = os.pullEvent
should be
local oldPullEvent = os.pullEvent
MistahEpic #10
Posted 22 April 2013 - 02:23 AM
line 1 local oldPellEvent = os.pullEvent
should be
local oldPullEvent = os.pullEvent

that was it, dude. the tiniest mistakes are always the hardest to find. anyway, its finally done, no more revision needed. thanks to everyone who helped me, and heres the entire thing in working order in case anyone wants to use it.



local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
local password = "pass"
local engineer = "ssap"

term.clear()
term.setCursorPos(1,1)
print("Welcome. Please enter password.")
print("")
term.write("Enter Password: ")
local input = read("*")

if input == password then
print("")
print("Access Granted")
rs.setOutput("left",true)
sleep(4)
rs.setOutput("left",false)
os.reboot()
elseif input == engineer then
print("")
print("Engineer Status Confirmed")
sleep(3)
term.clear()
term.setCursorPos(1,1)
os.pullEvent = oldPullEvent
else
print("")
print("Access Denied")
sleep(3)
os.reboot()
end

;)/>
BigSHinyToys #11
Posted 22 April 2013 - 02:30 AM
Yes one bad character can cause a pile of problems .That is why attention to detail is important in program writing. Granted normally a error code helps but in this case that wouldn't have work.