Jump to content




Variable String problem


  • You cannot reply to this topic
7 replies to this topic

#1 mttasch1

  • Members
  • 10 posts

Posted 25 September 2012 - 09: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



#2 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 25 September 2012 - 09:04 PM

Password = {}
Make "local Password"
get rid of that

#3 Matrixmage

  • Members
  • 116 posts
  • LocationAt my Computer coding for the Computer in my Computer

Posted 25 September 2012 - 09: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/>

#4 Noodle

  • Members
  • 989 posts
  • LocationSometime.

Posted 25 September 2012 - 09:14 PM

View PostMatrixmage, on 25 September 2012 - 09:09 PM, said:

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.

#5 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 September 2012 - 09: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.

#6 mttasch1

  • Members
  • 10 posts

Posted 25 September 2012 - 11:41 PM

Thanks guys! I am amazed at how fast everyone responded, Certainly don't get that on most other forums... :P/>

#7 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 September 2012 - 11:59 PM

And that's why ComputerCraft = "awesome"

#8 Doyle3694

  • Members
  • 815 posts

Posted 26 September 2012 - 06: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






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users