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

Locked Startup Help

Started by UltimateHawkeye, 15 February 2015 - 11:21 AM
UltimateHawkeye #1
Posted 15 February 2015 - 12:21 PM
Hi there
To put my error into context I am trying to create a program that will show a startup screen and then go to a password entry application and after that run another application.
The code I am trying to use as follows:

Startup: http://pastebin.com/m6jQA73L
Lock: http://pastebin.com/dx303WtG

I get 2 outcomes from this code.
The first is that whenever the password is correct it stays on the screen. (does the same for incorrect password)
The second is if I get rid of that 3rd from last "end", it returns an error:
"bios:336: [string "lock"]:19: 'end' expected (to close 'while' at line 3)"

I thought I already had an end for the while at line 3.

Any help would be appreciated.

Cheers!
-Hawk
Quintuple Agent #2
Posted 15 February 2015 - 04:50 PM
I believe this is what you may have been going for
Spoiler

local password = "bacon"
local passtrue = "bleh"
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
  term.clear()
  term.setCursorPos(1,1)
  print("Password Correct!")
  passtrue = "Y"
end     --End for if input == password

if passtrue == "Y" then
   shell.run("desktop")
else
  print("Password Incorrect!")
  sleep(3)
end    --End for if passtrue == "Y"
end    --End for while statement
Notice how I moved one the ends to after you set passtrue to 'Y'
I also removed the local from setting passtrue to 'Y' because doing that would be declaring a new passtrue that is local to that if statement, so the other pass true in your script would not be set and never be equal to 'Y', it would always stay 'bleh'

However you could shorten it down to this
Spoiler

local password = "bacon"
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == password then
  term.clear()
  term.setCursorPos(1,1)
  print("Password Correct!")
  sleep(2)
  shell.run("desktop")
else
  print("Password Incorrect!")
  sleep(3)
end
end
Edited on 15 February 2015 - 03:57 PM