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

[Error] - Login program

Started by Cross_Sans, 19 June 2015 - 03:38 PM
Cross_Sans #1
Posted 19 June 2015 - 05:38 PM
[PS: If this post are not in the good section, please tell me !]

I create this program but i got a problem :
1. I set the password : login pass (for example). This draw gui..
2. When i type wrong text, i can pass.

You can download the program : pastebin get FUiBZ6DJ login

It's the program :

--Login program for MC - ComputerCraft Mod
--By Redall - This program is with GNU Public License, you can : modify, copy, rewrite the code, modify and post to me ([url="/cdn-cgi/l/email-protection"][email protected][/url]<script cf-hash='f9e31' type="text/javascript"> /* */</script>) or in the forum (http://www.computercraft.info/forums2/) !
--Lock computer with args
local tArgs = {...}
--Check pass on args
if #tArgs == 0 then
print("Usage: login <password>")
return
end
--CenterPrint API
function centerPrint(sText)
		local w, h		 = term.getSize()
		local x, y		 = term.getCursorPos()
		x				  = math.max(math.floor((w / 2) - (#sText / 2)), 0)
		term.setCursorPos(x, y)
		print(sText)
end
--CRead API
local function cread()
  local input = ''
  local x,y = term.getCursorPos()
  term.setCursorBlink(true)
  repeat
	term.setCursorPos(x,y)
	term.write(input)
	local ev, p1 = os.pullEvent()
	if ev == 'char' then
	  if #input < 48 then
		input = input .. p1
	  end
	elseif ev == 'key' then
	  if p1 == keys.backspace then
  term.clearLine()
  paintutils.drawLine(1, 7, 51, 7, BackgroundColor)
  paintutils.drawLine(2, 7, 49, 7, BackgroundColorForGui)
		input = input:sub(1, #input - 1)
	  end
	end
  until ev == 'key' and p1 == keys.enter
  term.setCursorBlink(false)
  return input
end
--Colors settings
--				 * Principal colors settings *				 --
BackgroundColor			= colors.orange
TextColor				  = colors.white
BackgroundColorForGui	  = colors.red
TextColorForGui			= colors.white
--					   * Special colors *					  --
ErrorColor				 = colors.red
WarningColor			   = colors.yellow
--			 * Settings for terminal size and pos *			--
local xTerm, yTerm		 = term.getSize()
xn, yn					 = xTerm - (xTerm - 1), yTerm - (yTerm - 1)
xtBox					  = xBox - (xBox - 1)
yBoxT					  = yTerm - (yTerm - 3)

--Begin settings								  
term.setBackgroundColor(BackgroundColor) -- Setting for background color
term.setTextColor(TextColor) -- Setting for text color
--Begin program
function gotopass()
term.clear()
paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
term.setCursorPos(xn, 2)
centerPrint("Computer Locked. Please enter password.")
term.setBackgroundColor(BackgroundColor)
term.setCursorPos(xn, 5)
centerPrint("Enter password :")
paintutils.drawLine(2, 7, 49, 7, BackgroundColorForGui)
term.setCursorPos(2, 7)
cread()
if input == pass then
  term.setBackgroundColor(BackgroundColor)
  term.clear()
  paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
  term.setCursorPos(xn, 2)
  centerPrint("You can pass.")
  sleep(1)
  term.setBackgroundColor(colors.black)
  term.clear()
  return
else
  term.setBackgroundColor(BackgroundColor)
  term.clear()
  paintutils.drawFilledBox(xn, yn, xTerm, yBoxT, BackgroundColorForGui)
  term.setCursorPos(xn, 2)
  centerPrint("Wrong pass.")
  sleep(1)
  term.setBackgroundColor(colors.black)
  term.clear()
  gotopass()
end
end
gotopass()
The_Cat #2
Posted 19 June 2015 - 06:08 PM

if input == pass then

On this line try putting the pass in quotes "pass" so you are comparing it to a string.

–EDIT

My bad i took another look at it, you need to make it so you are assigning pass with the tArgs[1] (Or just use tArgs[1]) and you need to assign a variable the return on the cread() function.

So…


input = cread()
if input == tArgs[1] then
Edited on 19 June 2015 - 04:22 PM
Cross_Sans #3
Posted 19 June 2015 - 06:15 PM

if input == pass then

On this line try putting the pass in quotes "pass" so you are comparing it to a string.

Sorry but i don't to compare with string. It's with a variable set on the up of the program. But thanks for your post! :)/>
Cross_Sans #4
Posted 19 June 2015 - 06:20 PM

if input == pass then

On this line try putting the pass in quotes "pass" so you are comparing it to a string.

–EDIT

My bad i took another look at it, you need to make it so you are assigning pass with the tArgs[1] (which is what the user imputed) and you need to use the return on the cread() function.

So…


input = cread()
if input == tArgs[1] then

Sorry but at the second code does not work !
The_Cat #5
Posted 19 June 2015 - 06:26 PM

if input == pass then

On this line try putting the pass in quotes "pass" so you are comparing it to a string.

–EDIT

My bad i took another look at it, you need to make it so you are assigning pass with the tArgs[1] (which is what the user imputed) and you need to use the return on the cread() function.

So…


input = cread()
if input == tArgs[1] then

Sorry but at the second code does not work !

I loaded up the program, changed just those two lines and it says theres a problem on line 55 "xtBox = xBox - (xBox - 1)"
Comment this line out and it will work.
Edited on 19 June 2015 - 04:27 PM
Cross_Sans #6
Posted 19 June 2015 - 06:28 PM

if input == pass then

On this line try putting the pass in quotes "pass" so you are comparing it to a string.

–EDIT

My bad i took another look at it, you need to make it so you are assigning pass with the tArgs[1] (which is what the user imputed) and you need to use the return on the cread() function.

So…


input = cread()
if input == tArgs[1] then

Sorry but at the second code does not work !

I loaded up the program, changed just those two lines and it says theres a problem on line 55 "xtBox = xBox - (xBox - 1)"
Comment this line out and it will work.

Sorry but i tested with this line and it's work perfectly :mellow:/> .
The_Cat #7
Posted 19 June 2015 - 06:31 PM
Sorry but i tested with this line and it's work perfectly :mellow:/>/> .

So its good?
Edited on 19 June 2015 - 04:32 PM
Cross_Sans #8
Posted 19 June 2015 - 06:32 PM
Sorry but i tested with this line and it's work perfectly :mellow:/>/> .

So its good?
So i rewrite the program ! Thanks for helping me ! :D/>