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

password before access user interface

Started by RealGaming, 17 October 2012 - 04:34 PM
RealGaming #1
Posted 17 October 2012 - 06:34 PM
hi everybody!
ive want a program that you first have to enter a password to turn on/off a nuclear reactor.
i want that you only can enter a fault password 3 times…
im new to this so id like to ask!
I already tried some things but nothing worked
can you guys please help me?

- Jesper
jag #2
Posted 17 October 2012 - 06:36 PM
I don't know if you know this, but if you name your program startup it will run on startup (a.k.a. when you start the computer/turtle)

And then it's just to make a login program, theres a lot of simples one out there!

And so if you want to be able to have a limit amount of tries, you can use mine :D/>/> :
CL3Ff3zQ
Now you'll have to edit this one ↑↑ to get it to do as you want when you fail the login, and to edit the limit amount of tries etc.
Currently it shutdown if you run out of tries, and it goes to the shell once you enter the correct password.
PixelToast #3
Posted 17 October 2012 - 08:02 PM
here i made a textbox type thing:
usage: textbox(label)
returns string or nil if you press ctrl to close it out


local function textbox(bartext)
term.setCursorBlink( true )
    local sLine = ""
local nPos = 0
local oW, oH = term.getSize()
local w,h=oW-4,math.floor(oH/2)
local sx,sy=4,math.floor(oH/2)
local function redraw()
  local nScroll = 0
  if sx + nPos >= w then
   nScroll = (sx + nPos) - w
  end
  term.setCursorPos(3,math.floor(oH/2)-1)
  write(string.rep("-",oW-5))
  term.setCursorPos(3,math.floor(oH/2)+1)
  write(string.rep("-",oW-5))
  term.setCursorPos(math.floor(oW/2)-math.floor(#bartext/2),math.floor(oH/2)-1)
  write(bartext)
  term.setCursorPos( sx, sy )
  term.write(term.write( string.rep(" ", w - sx + 1) ))
  term.setCursorPos( sx, sy )
  term.write(term.write( string.sub( sLine, nScroll + 1 ) ))
  term.setCursorPos(3,math.floor(oH/2))
  write("|")
  term.setCursorPos(oW-3,math.floor(oH/2))
  write("|")
  term.setCursorPos( sx + nPos - nScroll, sy )
end
redraw()
while true do
  local sEvent, param = os.pullEvent()
  if sEvent == "char" then
   sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
   nPos = nPos + 1
   redraw()
  elseif sEvent == "key" then
	  if param == 28 then
    break
   elseif param == 203 then
    if nPos > 0 then
	 nPos = nPos - 1
	 redraw()
    end
   elseif param == 205 then  
    if nPos < string.len(sLine) then
	 nPos = nPos + 1
	 redraw()
    end
   elseif param == 200 or param == 208 then
    if _tHistory then
	 if param == 200 then
	  if nHistoryPos == nil then
	   if #_tHistory > 0 then
	    nHistoryPos = #_tHistory
	   end
	  elseif nHistoryPos > 1 then
	   nHistoryPos = nHistoryPos - 1
	  end
	 else
	  if nHistoryPos == #_tHistory then
	   nHistoryPos = nil
	  elseif nHistoryPos ~= nil then
	   nHistoryPos = nHistoryPos + 1
	  end	 
	 end
	 if nHistoryPos then
					 sLine = _tHistory[nHistoryPos]
					 nPos = string.len( sLine )
				    else
	  sLine = ""
	  nPos = 0
	 end
	 redraw()
			    end
   elseif param == 14 then
    if nPos > 0 then
	 sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
	 nPos = nPos - 1	
	 redraw()
    end
   elseif param == 29 then
    term.setCursorBlink( false )
    return nil
   end
  end
end
term.setCursorBlink( false )
term.setCursorPos( w + 1, sy )
return sLine
end
jag #4
Posted 17 October 2012 - 08:05 PM
here i made a textbox type thing:
usage: textbox(label)
returns string or nil if you press ctrl to close it out

–snipped code–
Cool! So how does it work? How do we use it?
Is it just textbox("the text I want to be in a textbox")?
Or what do we use it for?
PixelToast #5
Posted 17 October 2012 - 08:55 PM

:3, it also rescales to different screen sizes, i plan on having color support later
RealGaming #6
Posted 18 October 2012 - 09:37 AM
thx!
i will try!
and then a other question, i want 2 if statements and then a else statement.
this is the code

————————————————-
if input == ""on"" then
term.clear()
term.setCursorPos(12,4)
print("TURNING ON NUCLEAR REACTOR")
sleep(3)
rs.setOutput("back", true)
shell.run("nuclear") – same program so you can turn it off again
if input == "off" then
term.clear()
term.setCursorPos(12,4)
print("TURNING OFF NUCLEAR REACTOR")
rs.setOutput("back', false)
shell.run("nuclear")
end
else

term.clear()
term.setCursorPos(12,4)
print("COMMAND NOT RECONIZED!")
sleep(3)
shell.run("nuclear")
end
——————————————————–

please help
if i type on, it does work
and when i type off it says the print("COMMAND NOT RECONIZED")
remiX #7
Posted 18 October 2012 - 01:33 PM
Spoiler

if input == ""on"" then
term.clear()
term.setCursorPos(12,4)
print("TURNING ON NUCLEAR REACTOR")
sleep(3)
rs.setOutput("back", true)
shell.run("nuclear") -- same program so you can turn it off again
if input == "off" then
term.clear()
term.setCursorPos(12,4)
print("TURNING OFF NUCLEAR REACTOR")
rs.setOutput("back', false)
shell.run("nuclear")
end
else

term.clear()
term.setCursorPos(12,4)
print("COMMAND NOT RECONIZED!")
sleep(3)
shell.run("nuclear")
end

More tips: make input into lower case so it will not be case sensitive (unless you want it to be - because right now, if you were to type On, ON or oN it will not activiate - It only will accept 'on')

Spoiler

input = string.lower(read())

if input == "on" then
  term.clear()
  term.setCursorPos(12,4)
  print("TURNING ON NUCLEAR REACTOR")
  sleep(3)
  rs.setOutput("back", true)
  shell.run("nuclear") -- same program so you can turn it off again
elseif input == "off" then
  term.clear()
  term.setCursorPos(12,4)
  print("TURNING OFF NUCLEAR REACTOR")
  rs.setOutput("back', false)
  shell.run("nuclear")
else
  print("COMMAND NOT RECOGNIZED!")
  sleep(3)
  shell.run("nuclear")
end