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

does any1 see the problem?

Started by sicet7, 11 June 2012 - 04:34 PM
sicet7 #1
Posted 11 June 2012 - 06:34 PM
hi i got help from mystic to this code but now is says this error and i wrote this exact thing


-- Prevent Termination
local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- Setup usernames and passwords
local tUsers = {
["sicet7"] = "joymax",
["sacho101"] = "Password2",
["Knirksen"] = "Password3",
["muldyr1995"] = "Password4"
}
local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end
-- Infinite loop
while true do
  clear()
  -- Ask for username
write("User: ")
local usr = read()
-- Check username
if tUsers[usr] ~= nil then
  -- Ask for password
  write("Password: ")
  local pass = read("*")
  -- Check password
  if pass == tUsers[usr] then
	print("Opening the door...")
	-- open door here
  else
	print("Wrong password")
	sleep(2)
  end
else
  print("No such user ", usr)
  sleep(2)
end
os.pullEvent = oldPullEvent

error msg: bios:206: [string "startup"]:51 'end' expected (to close 'while at line 21) FIXED THX

Edited
when ever i type sicet7 as a username it pop's up with an error

error msg: startup:29 attempt to index ? (a nil value)
MysticT #2
Posted 11 June 2012 - 06:46 PM
You are missing and end, to close the while loop. It should be:

-- Prevent Termination
local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- Setup usernames and passwords
local tUsers = {
["sicet7"] = "joymax",
["sacho101"] = "Password2",
["Knirksen"] = "Password3",
["muldyr1995"] = "Password4"
}

local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

-- Infinite loop
while true do
  clear()
  -- Ask for username
  write("User: ")
  local usr = read()
  -- Check username
  if tUsers[usr] ~= nil then
    -- Ask for password
    write("Password: ")
    local pass = read("*")
    -- Check password
    if pass == tUsers[usr] then
      print("Opening the door...")
      -- open door here
    else
      print("Wrong password")
      sleep(2)
    end
  else
    print("No such user ", usr)
    sleep(2)
  end
end

os.pullEvent = oldPullEvent