Jump to content




Opinion on my pocket password


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

#1 Krul__Tepes

  • Members
  • 17 posts

Posted 20 July 2017 - 09: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

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 20 July 2017 - 10: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).


#3 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 20 July 2017 - 11:02 PM

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.

#4 Krul__Tepes

  • Members
  • 17 posts

Posted 21 July 2017 - 04: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

#5 Dave-ee Jones

  • Members
  • 456 posts
  • LocationVan Diemen's Land

Posted 21 July 2017 - 05:54 AM

View PostKrul__Tepes, on 21 July 2017 - 04:15 AM, said:

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 by Dave-ee Jones, 21 July 2017 - 05:55 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users