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

My Custom OS does not boot!

Started by Jnick22, 12 September 2013 - 03:44 PM
Jnick22 #1
Posted 12 September 2013 - 05:44 PM
Title: My Custom OS does not boot!

Well, I am working on an OS and I have taken bits and parts of other programs (Im a stealer, I know. Its just for me and my friends so I am pretty sure it is ok)
Whenever I try to boot it I get this error

bios:339: [string "startup"]:12: unexpected symbol

Here is the code
Spoiler

while true do
os.pullEvent =os.pullEventRaw
term.clear()
term.setCursorPos(1, 1)
write("Please Enter Password: ")
input = read("*")
if input == "Password" then
shell.run("mainmenu")
elseif
  local nDataPrint = 0
  local nPassLen = math.random(5,8)
  local nGuesses = 4

  local aPass5 = {}
  local aPass6 = {}
  local aPass7 = {}
  local aPass8 = {}
  local nPass5 = 0
  local nPass6 = 0
  local nPass7 = 0
  local nPass8 = 0
  bBackDoor = false
  local file = io.open( "5letter.txt", "r" )
  local sLine = file:read()
  while sLine do
	table.insert(aPass5, sLine)
	nPass5 = nPass5 + 1
	sLine = file:read()
  end

  local file = io.open( "6letter.txt", "r" )
  local sLine = file:read()
  while sLine do
	table.insert(aPass6, sLine)
	nPass6 = nPass6 + 1
	sLine = file:read()
  end

  local file = io.open( "7letter.txt", "r" )
  local sLine = file:read()
  while sLine do
	table.insert(aPass7, sLine)
	nPass7 = nPass7 + 1
	sLine = file:read()
  end

  local file = io.open( "8letter.txt", "r" )
  local sLine = file:read()
  while sLine do
	table.insert(aPass8, sLine)
	nPass8 = nPass8 + 1
	sLine = file:read()
  end

  local aHex = {
	[0] = "0",
	[1] = "1",
	[2] = "2",
	[3] = "3",
	[4] = "4",
	[5] = "5",
	[6] = "6",
	[7] = "7",
	[8] = "8",
	[9] = "9",
	[10] = "A",
	[11] = "B",
	[12] = "C",
	[13] = "D",
	[14] = "E",
	[15] = "F"
  }
  local aAddr = {
	[0] = 15,
	[1] = math.random(0, 13),
	[2] = math.random(0, 15),
	[3] = math.random(0, 7) * 2
  }
  local aScreen = {}
  for n=1,18 do
	table.insert(aScreen, "")
  end
  local aData = {}
  local sData = ""

  for n=1,260 do
	r = math.random(33, 65)
	if r > 54 then
	  sData = sData .. string.char(46)
	elseif r > 47 then
	  sData = sData .. string.char(r + 10)
	else
	  sData = sData .. string.char(r)
	end
  end

  local r = 0
  local r2 = math.random(8,12)
  local aPasswords = {}
  for n=1,r2 do
	nNext = 0
	while nNext == 0 do
	  nSkip = 0
	  if nPassLen == 5 then
		local r3 = math.random(1,nPass5)
		for n2=1,n - 1 do
		  if aPass5[r3] == aPasswords[n2] then
			nSkip = 1
		  end
		end
		if nSkip == 0 then
		  table.insert(aPasswords, aPass5[r3])
		  nNext = 1
		end
	  elseif nPassLen == 6 then
		local r3 = math.random(1,nPass6)
		for n2=1,n - 1 do
		  if aPass6[r3] == aPasswords[n2] then
			nSkip = 1
		  end
		end
		if nSkip == 0 then
		  table.insert(aPasswords, aPass6[r3])
		  nNext = 1
		end
	  elseif nPassLen == 7 then
		local r3 = math.random(1,nPass7)
		for n2=1,n - 1 do
		  if aPass7[r3] == aPasswords[n2] then
			nSkip = 1
		  end
		end
		if nSkip == 0 then
		  table.insert(aPasswords, aPass7[r3])
		  nNext = 1
		end
	  elseif nPassLen == 8 then
		local r3 = math.random(1,nPass8)
		for n2=1,n - 1 do
		  if aPass8[r3] == aPasswords[n2] then
			nSkip = 1
		  end
		end
		if nSkip == 0 then
		  table.insert(aPasswords, aPass8[r3])
		  nNext = 1
		end
	  end
	end
  end

  local sCorrect = aPasswords[math.random(1,r2)]

  for n=1,r2 do
	r = r + nPassLen + math.random(3,(260 - (nPassLen * r2)) / r2 + 5)
	sData = string.sub(sData,1,r) .. aPasswords[n] .. string.sub(sData,r + nPassLen + 1,260)
  end

  for n=0,25 do
	table.insert(aData, string.sub(sData,n*10,n*10+9))
  end

  local function addrShift(int)
	aAddr[3] = aAddr[3] + int
	for n=0,2 do
	  if aAddr[3-n] > 15 then
		aAddr[3-n] = aAddr[3-n] - 16
		aAddr[3-n-1] = aAddr[3-n-1] + 1
	  end
	end
  end

  local function int2hex(int)
	return aHex[int]
  end

  local function addrString()
	return int2hex(aAddr[0]) .. int2hex(aAddr[1]) .. int2hex(aAddr[2]) .. int2hex(aAddr[3])
  end

  local function printString(str, x, y)
	local nLen = string.len(str)
	if nLen > 0 then
	  for n=1,nLen do
		term.setCursorPos( x+(n-1), y )
		io.write(string.sub(str, n, n))
		sleep(0.001)
	  end
	else
	  term.setCursorPos(x,y)
	  sleep(0.001)
	end
  end

  local function inputBox(len, x, y)
	local bInput = true
	local sOutput = ""
	local sTemp = ""
	local nTemp = 0
	local bLast = false
	local bFlash = false
	while bInput == true do
	  if nGuesses == 1 then
		if not bLast then
		  os.startTimer(0.5)
		  bFlash = not bFlash
		  bLast = true
		  term.setCursorPos(1,2)
		  io.write("!!! WARNING: LOCKOUT IMMINENT !!!")
		  term.setCursorPos(x,y)
		  io.write(sOutput)
		end
	  end
	  local sEvent, param = os.pullEvent()
	  if sEvent == "timer" then
		bFlash = not bFlash
		if bFlash then
		  term.setCursorPos(1,2)
		  io.write("!!! WARNING: LOCKOUT IMMINENT !!!")
		else
		  term.setCursorPos(1,2)
		  io.write("								 ")
		end
		os.startTimer(0.5)
		term.setCursorPos(x,y)
		io.write(sOutput)
	  end
	  if sEvent == "key" then
		if param == 28 then
		  if string.len(sOutput) == len then
			sTemp = ""
			for n=1,len do
			  nTemp = string.byte(string.sub(sOutput,n,n))
			  if nTemp > 96 then
				if nTemp < 123 then
				  nTemp = nTemp - 32
				end
			  end
			  sTemp = sTemp .. string.char(nTemp)
			end
			sOutput = sTemp
			term.setCursorPos(x,y)
			io.write(sOutput)
			bInput = false
		  end
		elseif param == 14 then
		  sOutput = string.sub(sOutput,1,string.len(sOutput)-1)
		  term.setCursorPos(x+string.len(sOutput),y)
		  io.write(" ")
		  term.setCursorPos(x+string.len(sOutput),y)
		end
	  end
	  if sEvent == "char" then
		if string.len(sOutput) < len then
		  sOutput = sOutput .. param
		  term.setCursorPos(x,y)
		  io.write(sOutput)
		end
	  end
	end
	return sOutput
  end
  term.setCursorBlink( true )
  term.clear()
  term.setCursorPos( 1, 1 )
  printString("WELCOME TO ROBCO INDUSTRIES (TM) TERMLINK", 1, 1)
  printString("", 1, 2)
  printString(">", 1, 3)
  sleep(1)
  printString("SET TERMINAL/INQUIRE", 2, 3)
  printString("", 1, 4)
  sleep(1)
  printString("RIT-V300", 1, 5)
  printString("", 1, 6)
  printString(">", 1, 7)
  sleep(1)
  printString("SET FILE/PROTECTION-OWNER:RWED ACCOUNTS.F", 2, 7)
  printString("", 1, 8)
  sleep(0.5)
  printString(">", 1, 8)
  sleep(1)
  printString("SET HALT RESTART/MAINT", 2, 8)
  printString("", 1, 9)
  sleep (1.8)
  printString("Initializing Robco Industries(TM) MF Boot Agent", 1, 10)
  printString("RETRO BIOS", 1, 11)
  printString("RBIOS-4.02.08.00 52EE5.E7.E8", 1, 12)
  printString("Copyright 2201-2203 Robco Ind.", 1, 13)
  printString("Uppermem: 64 KB", 1, 14)
  printString("Root (5A8)", 1, 15)
  printString("Maintenance Mode", 1, 16)
  printString("", 1, 17)
  printString(">", 1, 18)
  sleep (1)
  printString("RUN DEBUG/ACCOUNTS.F\n", 2, 18)
  sleep(0.5)
  term.clear()

  printString("ROBCO INDUSTRIES (TM) TERMLINK PROTOCOL",1,1)
  printString("ENTER PASSWORD NOW",1,2)
  printString("",1,3)
  printString("4 ATTEMPT(S) LEFT: * * * *",1,4)


  for n=1,13 do
	nDataPrint = nDataPrint + 1
	printString("0x" .. addrString() .. " " .. aData[nDataPrint],1,n+5)
	addrShift(10)
  end
  for n=1,13 do
	nDataPrint = nDataPrint + 1
	printString("0x" .. addrString() .. " " .. aData[nDataPrint],19,n+5)
	addrShift(10)
  end
  printString(">",37,18)


  local sGuess = ""

  local function  showChat()
	for n=2,16 do
	  term.setCursorPos(37,n)
	  io.write(aScreen[n])
	end
  end

  local function addLine(str)
	for n=1,15 do
	  aScreen[n] = aScreen[n+1]
	end
	while string.len(str) < 13 do
	  str = str .. " "
	end
	aScreen[16] = str
	showChat()
	sleep(0.1)
  end

  local function guessLeft()
	sGuessText = nGuesses .. " ATTEMPT(S) LEFT: "
	for n=1,nGuesses do
	  sGuessText = sGuessText .. "* "
	end
	sGuessText = sGuessText .. "	   "
	term.setCursorPos(1,4)
	io.write(sGuessText)
  end


  while nGuesses > 0 do
	sGuess = inputBox(nPassLen,38,18)
	term.setCursorPos(38,18)
	io.write("		  ")
	if sGuess == sCorrect then
	  addLine(">" .. sGuess)
	  addLine(">Exact Match!")
	  addLine(">Please wait")
	  addLine(">while system")
	  addLine(">is accessed")
	  term.setCursorPos(38,18)
	  sleep(2)
	  nGuesses = 0
	else
	  local nPartRight = 0
	  for n=1,nPassLen do
		if string.sub(sGuess,n,n) == string.sub(sCorrect,n,n) then
		  nPartRight = nPartRight + 1
		end
	  end
	  addLine(">" .. sGuess)
	  addLine(">Entry denied")
	  addLine(">" .. nPartRight .. "/" .. nPassLen .. " correct")
	  nGuesses = nGuesses - 1
	  guessLeft()
	  term.setCursorPos(38,18)
	end
  end
  if sGuess == sCorrect then
	shell.run("mainmenu")
  else
	for n=1,8 do
	  sleep(0.1)
	  print("")
	end
	printString("TERMINAL LOCKED\n",18,18)
	print("")
	sleep(0.1)
	print("")
	printString("PLEASE CONTACT AN ADMINISTRATOR\n",10,18)
	print("")
	for n=1,6 do
	  sleep(0.1)
	  print("")
	end
	term.setCursorBlink( false )
	local bLocked = true
	while bLocked do
	  local sEvent, param = os.pullEvent()
	  if sEvent == "redstone" then
		if redstone.getInput("bottom") then
		  bLocked = false
		end
	  end
	end
	term.setCursorBlink( true )
	term.clear()
	term.setCursorPos( 1, 18 )
	printString("Restarting...",1,1)
	sleep(5)
	term.clear()
	term.setCursorPos( 1, 18 )
	end
  if not bBackDoor then
	os.shutdown()
  end

It also uses some folders with seperate programs in them, but they worked before I added in the
personal password system. Any help appreciated!!
Bubba #2
Posted 12 September 2013 - 08:33 PM
Look here:

if input == "Password" then
shell.run("mainmenu")
elseif <-- This line

It should be:

if input == "Password" then
shell.run("mainmenu")
else <-- Change it to this
Jnick22 #3
Posted 13 September 2013 - 06:21 AM
Now I get error
bios:339: [string "startup"] :424: 'end' expected
(to close 'if' at line 7)

Any help appreciated :S
Kingdaro #4
Posted 13 September 2013 - 06:26 AM
If you look at the script's tabbing, you notice it ends with one tabbed off to the right. That indicates a missing end, as does your error, which explicitly says that an end is expected to close the if on line 7.