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

[Lua][Error] Password Lock Door

Started by Lunaus, 19 November 2012 - 12:06 PM
Lunaus #1
Posted 19 November 2012 - 01:06 PM
Hello, I've posted this Minecraft and decided to go ahead and join here for quicker and better responses (if that thread gets any). I'll just copy what I have there and go into further detail.

Hello! I'm in a bit of need of help, I'm new to using tekkit and the majority of the mods within it. As of recent I have been learn to use the computercraft bit of tekkit mods while my other builders are tapping into other mods. I watched and follow THIS youtube video and I seem to have the " :16: " line issue like a few other commentors and the uploader has yet to answer them. So in hopes of getting this fixed for myself as well as getting an answer for anyone else watching the video and getting stuck like myself and others have I'm here asking for any assistance from anyone whose messed around with this mod and knows a bit about the programming know-how behind it.

So here's my code:
Spoiler

os.pullEvent = os.pullEventRaw
local side = "back"
local password = "PASSWORD"
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password:")
local input = read"*"
term.clear()
term.setCursorPos(1,1)
if input == password then
print("Welcome Home")
rs.setOutput(side.true)
sleep(opentime)
rs.setOutput(side.false)
os.reboot()
else
term.clear()
term.setCursoPos(1,1)
print("Incorrect Password")
print("Please Try Again")
sleep(5)
os.reboot
end


I don't know what's wrong with the "else" but the computer says the '<name>' has something to do with it.

I got a string error on line 16 stating something about the name? I'm not familiar with snytax/lau I'm more of a HTML coder myself so I'm at a lose here as to what the problem might be and what I should do to fix it. Any and all help is appreciated so long as it doesn't change the fact that I'd like for this computer in question to just password protect door(s).
Doyle3694 #2
Posted 19 November 2012 - 01:11 PM
your last os.reboot is missing a () and your rs.setOutput()'s should have (side , true) and (side , false)
Doyle3694 #3
Posted 19 November 2012 - 01:33 PM
and oh:

term.setCursoPos(1,1)

miss-spell in "cursor"
Lunaus #4
Posted 19 November 2012 - 01:54 PM
your last os.reboot is missing a () and your rs.setOutput()'s should have (side , true) and (side , false)

What do you mean? Both lines of rs.setOutput() is either true or false, are you implying I should change the period to a comma?
Orwell #5
Posted 19 November 2012 - 02:13 PM
your last os.reboot is missing a () and your rs.setOutput()'s should have (side , true) and (side , false)

What do you mean? Both lines of rs.setOutput() is either true or false, are you implying I should change the period to a comma?
Yes, that's what he's saying. :(/>/> And it's the truth. :(/>/>
Lunaus #6
Posted 19 November 2012 - 02:34 PM
your last os.reboot is missing a () and your rs.setOutput()'s should have (side , true) and (side , false)

What do you mean? Both lines of rs.setOutput() is either true or false, are you implying I should change the period to a comma?
Yes, that's what he's saying. :(/>/> And it's the truth. :(/>/>

Alright well the computer is still giving me an error on line 16 which is the "else".

Edit: I scrapped my old code mostly and incorporated something from the TekkitVideoWiki video on password locks for doors.
The password works great! But I must ask is there a way for the computer to auto exit you out of the screen interface?

New code by the way:
Spoiler

os.pullEvent = os.pullEventRaw

local side = "back"
local password = "PASSWORD"
local opentime = 3

term.clear()
term.setCursorPos(1,1)

write("Password:")
local input = read"*"
term.clear()
term.setCursorPos(1,1)
if input == password then
print("Welcome Home")
redstone.setOutput (side , true)
sleep(3)
redstone.setOutput (side , false)
else
term.clear()
textutils.slowPrint ("Incorrect Password, Please Try Again")
sleep(5)
end
os.shutdown()
Orwell #7
Posted 19 November 2012 - 02:36 PM
Please post your current code again, because I'm not sure what you've corrected by now..
Lunaus #8
Posted 19 November 2012 - 03:27 PM
My newest code is in my comment before yours, the original is still the same in the first post.
Orwell #9
Posted 19 November 2012 - 05:17 PM
The password works great! But I must ask is there a way for the computer to auto exit you out of the screen interface?
I am afraid that's not possible. Except if you force the player to be too far away from the computer.
remiX #10
Posted 19 November 2012 - 06:16 PM
Would be awesome if you could do that though :/
Orwell #11
Posted 19 November 2012 - 06:31 PM
Crazy way to do that would be the following. Label the pc and put the program in startup. Then put a mining turtle next to it with this in startup:

turtle.dig()
turtle.place()
peripheral.call('front','turnOn')
turtle.shutdown()

Then on the pc it's simply:

peripheral.call(turtleSide,'turnOn')

If you need persistent data, well, have fun. :(/>/>
mibac138 #12
Posted 20 November 2012 - 01:22 AM
os.pullEvent() = os.pullEventRaw()

local side = "back"
local password = "PASSWORD"
local opentime = 3

term.clear()
term.setCursorPos(1,1)

write("Password: ")
 local input = read"*"
 term.clear()
 term.setCursorPos(1,1)
  if input == password then
  print("Welcome Home")
  redstone.setOutput(side , true)
  sleep(3)
  redstone.setOutput(side , false)
 else
  term.clear()
  textutils.slowPrint ("Incorrect Password, Please Try Again")
  sleep(5)
end
os.shutdown()
Lunaus #13
Posted 20 November 2012 - 10:11 AM
Crazy way to do that would be the following. Label the pc and put the program in startup. Then put a mining turtle next to it with this in startup:

turtle.dig()
turtle.place()
peripheral.call('front','turnOn')
turtle.shutdown()

Then on the pc it's simply:

peripheral.call(turtleSide,'turnOn')

If you need persistent data, well, have fun. :(/>/>

Lol, thank you! I might try just to see the effect. One last question though, I don't want anyone messing with my computer, but I'd like to password protect more than just a door and be able to go back in and change the password or any other string line if need be. Is there a way to have the OS ignore Ctrl+T and I'd still be able to access the code(s) on the computer?
remiX #14
Posted 20 November 2012 - 10:40 AM
What do you mean still access the codes? It is? Do you mean a os.pullEvent()?
Orwell #15
Posted 20 November 2012 - 11:48 AM
I think that he wants to be able to still get into the command prompt. It's rather simple. When the right password is entered, you could let it rest for 2 seconds or so. When you hit a key then, it goes to command line. This is an example (an adaption of your code):

os.pullEvent = os.pullEventRaw
local side = "back"
local password = "PASSWORD"
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password:")
local input = read"*"
term.clear()
term.setCursorPos(1,1)
if input == password then
  print("Welcome Home")
  redstone.setOutput (side , true)
  os.startTimer(3)
  while true do  -- this loop still sleeps 3 seconds, but also listens for a key event
	local e = os.pullEvent()
	if e == 'key' then
	  redstone.setOutput(side,false)
	  return -- go out of the program -> in shell
	elseif e == 'timer' then
	  break
	end
	redstone.setOutput (side , false)
else
  term.clear()
  textutils.slowPrint ("Incorrect Password, Please Try Again")
  sleep(5)
end
os.shutdown()
Lunaus #16
Posted 20 November 2012 - 01:06 PM
What do you mean still access the codes? It is? Do you mean a os.pullEvent()?

Yes.

I think that he wants to be able to still get into the command prompt. It's rather simple. When the right password is entered, you could let it rest for 2 seconds or so. When you hit a key then, it goes to command line. This is an example (an adaption of your code):

os.pullEvent = os.pullEventRaw
local side = "back"
local password = "PASSWORD"
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password:")
local input = read"*"
term.clear()
term.setCursorPos(1,1)
if input == password then
  print("Welcome Home")
  redstone.setOutput (side , true)
  os.startTimer(3)
  while true do  -- this loop still sleeps 3 seconds, but also listens for a key event
	local e = os.pullEvent()
	if e == 'key' then
	  redstone.setOutput(side,false)
	  return -- go out of the program -> in shell
	elseif e == 'timer' then
	  break
	end
	redstone.setOutput (side , false)
else
  term.clear()
  textutils.slowPrint ("Incorrect Password, Please Try Again")
  sleep(5)
end
os.shutdown()

She, and thank you I will give this a go! Now I do have to ask I can hit any key? I don't want to enter this and then find out later that I need to hit a specific key lol.

EDIT: Hm.. when I entered your code I got an error on line 28. Error prompt: bois:206: [string "startup"]:28: 'end' expected (to close 'while' at line 19)
Orwell #17
Posted 20 November 2012 - 03:01 PM
Little mistake, corrected:

os.pullEvent = os.pullEventRaw
local side = "back"
local password = "PASSWORD"
local opentime = 3
term.clear()
term.setCursorPos(1,1)
write("Password:")
local input = read"*"
term.clear()
term.setCursorPos(1,1)
if input == password then
  print("Welcome Home")
  redstone.setOutput (side , true)
  os.startTimer(3)
  while true do  -- this loop still sleeps 3 seconds, but also listens for a key event
	local e = os.pullEvent()
	if e == 'key' then
	  redstone.setOutput(side,false)
	  return -- go out of the program -> in shell
	elseif e == 'timer' then
	  break
    end
  end
  redstone.setOutput (side , false)
else
  term.clear()
  textutils.slowPrint ("Incorrect Password, Please Try Again")
  sleep(5)
end
os.shutdown()
Lunaus #18
Posted 20 November 2012 - 03:50 PM
Start:10: attempt to call nil lol
Op, that was all on me. I added another write line C:
All is good!