Jump to content




Error bioss:366 'end' expected in my security program please help!

help computer

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

#1 Maxwell0156

  • New Members
  • 2 posts

Posted 17 August 2014 - 09:23 PM

The Error I am Getting is bios:366: [string "startup"]:12: 'end'expected (to close 'if' at line 10)
I have looked at the code for many hours and can't figure it out please help! And yes I know that the error means that there's not enough block ends but I've looked and looked and I think I should be getting a eof not an end error. If you see any other ways to fix any bugs or improve the code please tell me I've been using cumputer craft to learn about lua so I would love it if you could help with that to thanks :).

--Variables
pass = "12345"
maxFails = "3"
numFails = "0"

--Functions

  --check Passcode
function checkPasscode()
  if io.read == pass then
	return true
	numFails = 0
  else
	return false
	numFails = numFails + 1
	end
  end
end

  --Check Fails
function checkFails()
  if checkPasscode() == false then
	if numFails == maxFails then
	  return true
	else if numFails > maxFails then
	  return true
  elseif checkPasscode() == true then
	return false
  else
	return false
	end
  end
end

  --Fails Seter
function setFails()

  if checkFails() == true then
	if checkPasscode() false then
	numFails = numFails + 1
	return true

  elseif check Fails() == false then
	numFails = 0
	return true

  else
	return false

--clear
function clear()
  term.clear
  term.setCursorPos(1,1)
end
--Looped Code
while true do
clear()

print("										  ")
print("		   Enter Your Passcode.		   ")
print("				  o-----o				 ")
write("				  |	 |				 ")
print("				  o-----o				 ")
term.setCursorPos(28,4)
if checkPasscode() == true then
  setFails()
  term.clear
  term.setCursorPos(1,2)
  io.read("*")
  print("		   o-----------------o")
  print("		   |Correct Passcode!|")
  print("		   |				 |")
  print("		   | Access Granted! |")
  print("		   o-----------------o")
  sleep(3)
  term.clear
  io.read()
  print("		 o----------------------o")
  print("		 |	Security  Mode	|")
  print("		 o----------------------o")
  print("		 |Press 1 to Activate   |")
  print("		 |Prees 2 to DeActivate |")
  print("		 o----------------------o")
  if io.read == 1 then
	term.clear
	print("			   Activated")
	rs.setOutput("back",true)
	sleep(15)
  else if io.read == 2 then
	term.clear
	print("			  DeActivated")
	rs.setOutput("back",false)
	sleep(4)
  else
	term.clear
	print("			 Unknown Input")
	sleep(3)
	term.clear
else if checkPasscode == false then
  setFails()
  print("			  Wrong  passcode")
  sleep(3)
  if checkFails == true then
	setFails()
	print("   To Many Fails Kicked from system for 30 seconds.")
	sleep(30.2)
	term.clear
  else if checkFails == false then
	print("					 Try Agin")
	sleep(5)
  term.clear
	end
  end
end

Edited by theoriginalbit, 18 August 2014 - 02:10 AM.


#2 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 17 August 2014 - 09:59 PM

first of all, you put your code in the [ CODE ] [ / CODE ] brackets. The error means you forgot an end somewhere. I would suggest using indentations in your code and you would see in in no-time.

#3 RickiHN

  • Members
  • 15 posts

Posted 17 August 2014 - 10:14 PM

--check Passcode
function checkPasscode()
   if io.read == pass then
	  return true
	  numFails = 0
   else
	  return false
	  numFails = numFails + 1
   end
end
end <----????


#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 18 August 2014 - 02:19 AM

Additionally to what RickiHN pointed out with your extra end, it should also be noted that you have a statement after the return false, in the checkPasscode function, this is in particular what it is complaining about.

Additionally you'll receive an error along the lines of = expected due to the fact that you're never calling the term.clear function, it should be term.clear() which interestingly enough you have actually defined a function clear but never use it.

If statements should be formatted like so
if condition then
  --# code if true
end

if condition then
  --# code if true
else
  --# code if false
end

if condition1 then
  --# if condition1 is true
elseif condition2 then
  --# if condition1 is false and condition2 is true
end

if condition1 then
  --# if condition1 is true
elseif condition2 then
  --# if condition1 is false and condition2 is true
else
  --# if both condition1 and condition2 are false
end
making use of these structures will reduce your problem with missing ends in the future.

#5 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 18 August 2014 - 03:36 AM

--Variables
pass = "12345"
maxFails = "3"
numFails = "0"
Your code is off here.
There are 5 basic kinds of things in lua, they are the fundamental parts and can make the simplest programs run or the most complicated programs run.
They are as such; Operators, Variables, Strings, Numbers, and Functions.

Operators:
Spoiler

Variables:
Spoiler

Strings:
Spoiler

Numbers:
Spoiler

Functions:
Spoiler
So there you go, the 5 most basic things lua uses. Now you should know enough to know that you should change "3" and "0" to 3 and 0.

Edited by Dragon53535, 18 August 2014 - 03:54 AM.


#6 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 18 August 2014 - 11:09 PM

function checkPasscode()
  if io.read == pass then
		return true
		numFails = 0
  else
		return false
		numFails = numFails + 1
  end
end
end
There are some things here you should work on and know for future reference. Firstly, io.read is a function and as such much have parenthesis (). So that line should be
if io.read() == pass then
Secondly inside of that if, you're returning true, now return works in the sense that it's leaving the function right then and there, and as such anything after that is negligible. This is where your error is as the computer is seeing it as
if io.read == pass then
  return true
numFails = 0
else
And so the program thinks that since it's returning, and the next thing isn't an else or elseif, then the if must be done and needs an end. the easy way to fix that is to just put numFails = 0 before the return. You should also do that inside of the else as well.

Finally to finish off that function, you have one too many ends at the end which you can see very easily with proper indentation. A great place to start learning proper indentation is a tutorial made by robhol here. It's super simple and it shows how much it helps to indent.

Edited by Dragon53535, 18 August 2014 - 11:14 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users