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

Opinion on my pocket password

Started by Krul__Tepes, 20 July 2017 - 08:28 PM
Krul__Tepes #1
Posted 20 July 2017 - 10:28 PM
please tell me if anything could be improved

Local color = colors.purple

oldPull = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
term.setTextColor(color)
print(“=========================”)
print(“=========Zphone 2=========”)
print(“=========================”)
print(“=== ===”)
print(“== ==”)
print(“== Username: Chronoa ==”)
print(“== Password: ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“== ==”)
print(“=== ===”)
print(“==== ====”)
term.setCursorPos(16,6)
If read(“*”) == “password” then
sleep(1)
term.clear()
term.setCursorPos(1,1)
Else
term.setCursorPos(6,8)
print(“Incorrect Login “)
sleep()
term.setCursorPos(6,9)
print(“Rebooting…”)
sleep(1)
term.clear()
term.setCursorPos(16,6)
os.reboot()

end

it removed alot of the spaces :P/>
KingofGamesYami #2
Posted 20 July 2017 - 11:14 PM
The clear and cursor set immediately before os.reboot are extraneous. I would also make a multiline string which is printed once as opposed to calling print over and over.

It's also not ideal to reboot constantly, as a simple loop would suffuice (this invalidates my comment about extraneous calls, if you choose to implement it).
Dave-ee Jones #3
Posted 21 July 2017 - 12:02 AM
Good use of term clearing and setting the cursor. Just adds better compatibility for testing and things like that (could be all over your screen if you didn't reboot it).

You don't need to use read in an if statement. It's better to put it in a variable and reference to it later. E.g.

local userInput = read("*")
if userInput == "password" then
-- Correct
else
-- Incorrect
end

May be an idea to chuck the whole thing in a while loop, but it doesn't really matter.
Krul__Tepes #4
Posted 21 July 2017 - 05:15 AM
KingofGamesYami removing the term.clear() before os.reboot makes where i type the password go down a line

Dave-ee Jones i tried what you said and it broke the program or it made the typing go down a line
Dave-ee Jones #5
Posted 21 July 2017 - 06:54 AM
KingofGamesYami removing the term.clear() before os.reboot makes where i type the password go down a line

Dave-ee Jones i tried what you said and it broke the program or it made the typing go down a line

Your reply to Yami is normal - it will go down because it will start where the cursor is when you run the program.

Which bit did you try? Putting it in a while loop? What you need to do is something like this:


while true do
  -- Your whole program here, basically
  sleep(0) -- Keeps the program running forever, otherwise it will eventually error out (probably don't need it as you already have some sleeps)
end
Edited on 21 July 2017 - 04:55 AM