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

Simple Boot Screen (v1.1)

Started by DefiledCobra, 23 September 2012 - 11:59 PM
DefiledCobra #1
Posted 24 September 2012 - 01:59 AM
I whipped up probably my first script, and it makes the bootup a bit more realistic and interesting. When it boots up, you are prompted with a login screen. The default username is Admin (or admin). They both work, but are case-sensitive. The password is banana…but you can change that if you like.

Now, I'm not going to take all of the credit because I did receive help from KaoS and Fatal_Exception… so thanks for the help!
Here's the code.

os.pullEvent = os.pullEventRaw
local function pause(key)
  print('Press X to continue.')
  while true do
	local sEvent, sParam=os.pullEvent('char')
	if string.lower(sParam)==key then
   break
	end
  end
end
term.clear()
sleep(0.3)
term.setCursorPos(15,2)
print("CraftOS is starting...")
term.setCursorPos(20,4)
print("----------")
sleep(0.5)
term.setCursorPos(20,4)
print("o---------")
sleep(0.5)
term.setCursorPos(20,4)
print("oo--------")
sleep(0.5)
term.setCursorPos(20,4)
print("ooo-------")
sleep(0.5)
term.setCursorPos(20,4)
print("oooo------")
sleep(0.5)
term.setCursorPos(20,4)
print("ooooo-----")
sleep(0.5)
term.setCursorPos(20,4)
print("oooooo----")
sleep(0.5)
term.setCursorPos(20,4)
print("ooooooo---")
sleep(0.5)
term.setCursorPos(20,4)
print("oooooooo--")
sleep(0.5)
term.setCursorPos(20,4)
print("ooooooooo-")
sleep(0.5)
term.setCursorPos(20,4)
print("oooooooooo")
sleep(1.0)
term.clear()
term.setCursorPos(21,2)
print("Welcome!")
sleep(2.5)
local intcount=0
term.clear()
term.setCursorPos(1,1)
print("Login")
while true do
  write("Username: ")
  userNameInput = read()
  if userNameInput == "admin" then
  sleep(1)
   break
  elseif userNameInput == "Admin" then
  sleep(1)
   break
  else
  sleep(1)
   print("Username not found.")
   intcount=intcount+1
   sleep(1)
   for i=3,2,-1 do
	term.setCursorPos(1,i)
	term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an invalid username too many times.')
   sleep(5)
   os.shutdown()
  end
end
local intcount=0
while true do
  write("Password: ")
  passwordInput = read("*")
  print("Verifying login...")
  sleep(2.5)
  if passwordInput == "banana" then
  print("Loading your settings...")
  sleep(1.5)
  print("Logging in...")
  sleep(3.5)
  term.clear()
  term.setCursorPos(1,1)
   print("Welcome to CraftOS!")
   pause('x')
   term.setCursorPos(1,2)
   term.clearLine()
   break
  else
   print("The password you have entered is incorrect.")
   intcount=intcount+1
   sleep(1)
   for i=6,3,-1 do
	term.setCursorPos(1,i)
	term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an incorrect password too many times.')
   sleep(5)
   os.shutdown()
  end
end

There may be excess code, but I'm just beginning to scratch the surface of LUA. :P/>/>
Edit: I made the bootup a bit faster, and added a welcome screen.
cant_delete_account #2
Posted 24 September 2012 - 02:10 AM
It has a useless loading screen, why?
DefiledCobra #3
Posted 24 September 2012 - 02:16 AM
It's mainly for aesthetics. If you don't like it, remove it.
stilldabomb #4
Posted 24 September 2012 - 03:15 AM
Eh, it's ok… Could use some work here and there. Also,
print('Press X to continue.')
should be
print('Press '..key..' to continue.')

but other than that it looks really nice…
Mr. Fang #5
Posted 24 September 2012 - 01:45 PM
I like Aesthetic programs, it makes it work nicer and look wayy better.
Good work!
ChiknNuggets #6
Posted 24 September 2012 - 02:07 PM
I hope you dont find this insulting or anything but, i just wanted to let you know how you could improve it, in the code below i removed about 30 lines of code and no actual function was changed, i put the progress strings into a table which allows you to just use for i=1,#progressbar do, which cut out all the repetitive lines, and then with the "Admin" or "admin" adding string.lower("userNameInput") == "admin" basically it just lowers all the text to make it not case sensitive, once again not trying to insult ur code i like it, i just thought it might help


os.pullEvent = os.pullEventRaw
local function pause(key)
  print('Press X to continue.')
  while true do
	    local sEvent, sParam=os.pullEvent('char')
	    if string.lower(sParam)==key then
   break
	    end
  end
end
local progressbar = {"----------","o---------","oo--------","ooo-------","oooo------","ooooo-----","oooooo----","ooooooo---","oooooooo--","ooooooooo-","oooooooooo"} -- added the possible strings into a table
term.clear()
sleep(0.3)
term.setCursorPos(15,2)
print("CraftOS is starting...")
for i=1,#progressbar do
term.setCursorPos(20,4)
print(progressbar[i])
sleep(0.5)
end
sleep(1.0)
term.clear()
term.setCursorPos(21,2)
print("Welcome!")
sleep(2.5)
local intcount=0
term.clear()
term.setCursorPos(1,1)
print("Login")
while true do
  write("Username: ")
  userNameInput = read()
  if string.lower(userNameInput) == "admin" then
   sleep(1)
   break
  else
  sleep(1)
   print("Username not found.")
   intcount=intcount+1
   sleep(1)
   for i=3,2,-1 do
	    term.setCursorPos(1,i)
	    term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an invalid username too many times.')
   sleep(5)
   os.shutdown()
  end
end
local intcount=0
while true do
  write("Password: ")
  passwordInput = read("*")
  print("Verifying login...")
  sleep(2.5)
  if passwordInput == "banana" then
  print("Loading your settings...")
  sleep(1.5)
  print("Logging in...")
  sleep(3.5)
  term.clear()
  term.setCursorPos(1,1)
   print("Welcome to CraftOS!")
   pause('x')
   term.setCursorPos(1,2)
   term.clearLine()
   break
  else
   print("The password you have entered is incorrect.")
   intcount=intcount+1
   sleep(1)
   for i=6,3,-1 do
	    term.setCursorPos(1,i)
	    term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an incorrect password too many times.')
   sleep(5)
   os.shutdown()
  end
end
DefiledCobra #7
Posted 25 September 2012 - 02:24 AM
Eh, it's ok… Could use some work here and there. Also,
print('Press X to continue.')
should be
print('Press '..key..' to continue.')

but other than that it looks really nice…

Oh yeah I know that. I changed it to that because when it was key it displayed a lower case x, which has always been a pet-peeve of mine. Otherwise, it would be that.


I hope you dont find this insulting or anything but, i just wanted to let you know how you could improve it, in the code below i removed about 30 lines of code and no actual function was changed, i put the progress strings into a table which allows you to just use for i=1,#progressbar do, which cut out all the repetitive lines, and then with the "Admin" or "admin" adding string.lower("userNameInput") == "admin" basically it just lowers all the text to make it not case sensitive, once again not trying to insult ur code i like it, i just thought it might help


os.pullEvent = os.pullEventRaw
local function pause(key)
  print('Press X to continue.')
  while true do
	    local sEvent, sParam=os.pullEvent('char')
	    if string.lower(sParam)==key then
   break
	    end
  end
end
local progressbar = {"----------","o---------","oo--------","ooo-------","oooo------","ooooo-----","oooooo----","ooooooo---","oooooooo--","ooooooooo-","oooooooooo"} -- added the possible strings into a table
term.clear()
sleep(0.3)
term.setCursorPos(15,2)
print("CraftOS is starting...")
for i=1,#progressbar do
term.setCursorPos(20,4)
print(progressbar[i])
sleep(0.5)
end
sleep(1.0)
term.clear()
term.setCursorPos(21,2)
print("Welcome!")
sleep(2.5)
local intcount=0
term.clear()
term.setCursorPos(1,1)
print("Login")
while true do
  write("Username: ")
  userNameInput = read()
  if string.lower(userNameInput) == "admin" then
   sleep(1)
   break
  else
  sleep(1)
   print("Username not found.")
   intcount=intcount+1
   sleep(1)
   for i=3,2,-1 do
	    term.setCursorPos(1,i)
	    term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an invalid username too many times.')
   sleep(5)
   os.shutdown()
  end
end
local intcount=0
while true do
  write("Password: ")
  passwordInput = read("*")
  print("Verifying login...")
  sleep(2.5)
  if passwordInput == "banana" then
  print("Loading your settings...")
  sleep(1.5)
  print("Logging in...")
  sleep(3.5)
  term.clear()
  term.setCursorPos(1,1)
   print("Welcome to CraftOS!")
   pause('x')
   term.setCursorPos(1,2)
   term.clearLine()
   break
  else
   print("The password you have entered is incorrect.")
   intcount=intcount+1
   sleep(1)
   for i=6,3,-1 do
	    term.setCursorPos(1,i)
	    term.clearLine()
   end
  end
  if intcount==3 then
   print('You have entered an incorrect password too many times.')
   sleep(5)
   os.shutdown()
  end
end

No no, this actually helps me learn! I am very new at LUA and feedback and corrections always help.
Luanub #8
Posted 25 September 2012 - 03:08 AM
Here's a post that you should read regarding "fake" loading screens, and what users think of them. They are very annoying and just a waste of the users time.

Fast/Functional programs > aesthetics.

http://www.computerc...2-fake-loading/
DefiledCobra #9
Posted 25 September 2012 - 04:12 AM
Didn't notice that. I apologize if I offended anybody, but you don't need to use it :P/>/>
stilldabomb #10
Posted 25 September 2012 - 04:36 AM
Eh, it's ok… Could use some work here and there. Also,
print('Press X to continue.')
should be
print('Press '..key..' to continue.')

but other than that it looks really nice…

Oh yeah I know that. I changed it to that because when it was key it displayed a lower case x, which has always been a pet-peeve of mine. Otherwise, it would be that.

You could change it to
print('Press '..string.upper(key)..' to continue.')
Thanks to actually listening to what I have to say, I think you're actually getting the hang of LUA, there are quite of things that could make it use less code. But I agree, if you don't like it, don't download it. Simple as that.
Also, you got Skype? I'll PM you my username if you do :P/>/>
TheOutcast5 #11
Posted 25 September 2012 - 10:38 AM
Stop hating the fake loading screens, as other people has said "you don't have to use them". Why can't you be nice and stop putting people down for adding them
DefiledCobra #12
Posted 25 September 2012 - 10:00 PM
Eh, it's ok… Could use some work here and there. Also,
print('Press X to continue.')
should be
print('Press '..key..' to continue.')

but other than that it looks really nice…

Oh yeah I know that. I changed it to that because when it was key it displayed a lower case x, which has always been a pet-peeve of mine. Otherwise, it would be that.

You could change it to
print('Press '..string.upper(key)..' to continue.')
Thanks to actually listening to what I have to say, I think you're actually getting the hang of LUA, there are quite of things that could make it use less code. But I agree, if you don't like it, don't download it. Simple as that.
Also, you got Skype? I'll PM you my username if you do :P/>/>

No, I don't. And yes, there are a lot of things that could be added to use less code. I just haven't discovered them yet.