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

Variable String problem

Started by mttasch1, 25 September 2012 - 08:03 PM
mttasch1 #1
Posted 25 September 2012 - 10:03 PM
First off, hello all. I am very new to Computer Craft, but I love it! It is a very well made mod.

Now to my problem, I am trying to create a script that accomplishes two things:
1. Easy password door script
2. I don't want to know their password (even though I could easily get it)

My idea so far has worked out in the form of a floppy disk, that I will hand to the person,
on top of a computer and a disk drive. The program is be named "startup", and as soon
as the person boots the computer with the floppy it goes right into the program. However,
I have been trying to make it so the script asks what you want the password to be, then
it will run the password door code afterwards. So the problem I have here is making someone
able to define the password, then using that password in the script. Another point I would like to
make here is that the whole floppy disk system is so no one can crack the person' password, unless
they retrieved the floppy disk and figure out how to take the program from it (which I only know how
to copy files to a disk, not retrieve them).


local pullEvent = os.pullEvent
local Password == {}
while true do
term.clear()
term.setCursorPos(1, 1)
write("Enter desired password:")
input = read()
Password = read()

while true do
  term.clear()
  termsetCursorPos(1, 1)
  print("Please enter password:")
  input = read("*")
  if input == Password then
   redstone.setOutput("left",true)
   redstone.setOutput("right",true)
   sleep(3)
   redstone.setOutput("right",false)
   redstone.setOutput("left",false)
  end
end

Noodle #2
Posted 25 September 2012 - 10:04 PM
Password = {}
Make "local Password"
get rid of that
Matrixmage #3
Posted 25 September 2012 - 10:09 PM
might be good to have "password = input" rather then them both having "read()". Just a suggestion. Also you didn't end your first while loop :P/>/>
Noodle #4
Posted 25 September 2012 - 10:14 PM
might be good to have "password = input" rather then them both having "read()". Just a suggestion. Also you didn't end your first while loop :P/>/>
His code takes a new password, but yes, password = input would be better so you don't have to type it twice.
Cranium #5
Posted 25 September 2012 - 10:29 PM
I saw this, and for some reason, accepted your challenge:

local function loadUser()
    local loadTable = {}
    local file = fs.open(".pass", "r")
    if file then
	    readLine = file.readLine()
	    while readLine do
		    local lineTable = {}
		    lineTable.user, lineTable.pass = string.match(readLine, "(%w+),(%w+)")
		    if lineTable.type then
			    table.insert(loadTable, lineTable)
		    end
		    readLine = file.readLine()
	    end
	    file.close()
    end
    return loadTable
end
--user check
local username,password = loadUser()
if usernamd == nil and password == nil then
term.clear()
term.setCursorPos(1,1)
write("Please choose your Username: ")
local user = read()
term.clear()
term.setCursorPos(1,1)
write("Please choose your Password: ")
local pass = read("*")
local file = fs.open(".password","w")
file.write(user..","..pass)
file.close()
else
while true do
  term.clear()
  termsetCursorPos(1,1)
  write("Please enter Username: ")
  local user = read()
  term.clear()
  termsetCursorPos(1,1)
  write("Please enter Password: ")
  local pass = read("*")
  if user == username and pass = password then
   redstone.setOutput("left",true)
   redstone.setOutput("right",true)
   sleep(3)
   redstone.setOutput("right",false)
   redstone.setOutput("left",false)
  end
end
end
This should do what you want.
mttasch1 #6
Posted 26 September 2012 - 12:41 AM
Thanks guys! I am amazed at how fast everyone responded, Certainly don't get that on most other forums… :P/>/>
Cranium #7
Posted 26 September 2012 - 12:59 AM
And that's why ComputerCraft = "awesome"
Doyle3694 #8
Posted 26 September 2012 - 07:21 PM
local answer
print("How would you discribe computercraft?")
answer = read()
if answer == "awesome" then
print("Yes indeed!!!")
elseif answer ~= "awesome" and answer ~= "bad" then
print("I'm not sure about that...")
else
print("GTFO")
end