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

bios:206 ')' expected

Started by LNETeam, 25 July 2012 - 02:03 PM
LNETeam #1
Posted 25 July 2012 - 04:03 PM
Hi I have a piece of code that runs a menu to create a password. I run it and get at line 28 "bios:206 ')' expected" Can anyone help me?

CODE:


os.loadAPI("/LNEX/APIS/WAPI")
function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
  if cEvent == "terminate" then
  end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
return x
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenu)
local nSelection = 0
local bLoop = true

while bLoop do
  term.clear()
  term.setCursorPos(1, 1)
  print(sMenuTitle)
  print()

  for nLine = 0, #mChoices do
   local sLine = "  "
   if nSelection == nLine then
	sLine = "> "
   end
   sLine = sLine .. mChoices[nLine]
   print(sLine)
  end

  local nWidth, nHeight = term.getSize()
  local y = nHeight
  local x = getRight("LNET Technologies")
  term.setCursorPos(x, y)
  term.write("LNET Technologies")

  local sEvent, nKey = os.pullEvent("key")

  if nKey == 200 then
   if mChoices[nSelection - 2] then
	nSelection = nSelection - 2
   end
  elseif nKey == 208 then
   if mChoices[nSelection + 2] then
	nSelection = nSelection + 2
   end
  elseif nKey == 28 then
   if mChoices[nSelection] then
	bLoop = false
	return nSelection
   end
  end
end
end
function menu()
repeat
  if nMenuNum == 0 then
   mChoices = {}
   mActions = {}
   mChoices[0] = "Login"
   mChoices[1] = " "
   if not fs.exists("/LNEX/data/retrieve/passuid") then
	mChoices[2] = "Create Account"
	mChoices[3] = " "
	mChoices[4] = "Shutdown"
	mChoices[5] = " "
	mChoices[6] = "Reboot"
	mActions[0] = function()
	 bMenuLoop = false
	 shell.run("/LNEX/Client/LNEX")
	end
	mActions[2] = function() nMenuNum = 1 end
	end
	mActions[4] = function()
	 term.clear()
	 os.shutdown()
	end
	mActions[6] = function()
	 term.clear()
	 os.reboot()
	end
	local nSelection = runMenu(mChoices, "LNEX Security Preface")
	mActions[nSelection]()
   else
	mChoices[2] = "Shutdown"
	mChoices[3] = " "
	mChoices[4] = "Reboot"
	mActions[0] = function() shell.run("/LNEX/Client/LNEX") end
	mActions[2] = function()
	 term.clear()
	 os.shutdown()
	end
	mActions[4] = function()
	 term.clear()
	 os.reboot()
	end
	local nSelection = runMenu(mChoices, "LNEX Security Preface")
	mActions[nSelection]()
   end
  elseif nMenuNum == 1 then
	local bChoice = WAPI.runChoiceMenu("Create permanent account?")
	if bChoice == true then
	 term.clear()
	 repeat
	  sNewPasscode = WAPI.runInputMenu("Please enter desired passcode:", true, true)
	 until sNewPasscode ~= ""
	 WFCI.fWrite("/LNEX/data/retrieve/passuid", sNewPasscode)
	 WAPI.slowPrint("Passcode set!")
	 nMenuNum
	else
	 nMenuNum = 0
	end
  end
until bMenuLoop == false
end
menu()
BigSHinyToys #2
Posted 25 July 2012 - 04:14 PM
I cant test this with out the API so I'm gessing here.

maby it is the
print(sMenuTitle)
as sMenuTitle is not defined in your code
or the
print()

print("")
is a better option for new lines

if not that the the error could be in the API

But as i said I'm guessing

[EDIT]
look at line 83 you have too many ends for this function

mActions[2] = function() nMenuNum = 1 end

[/EDIT]
LNETeam #3
Posted 25 July 2012 - 05:45 PM
Thanks that seemed to have worked. You were right about both the line 83 and the:
function runMenu(mChoices, sMenuTitle)
.
LNETeam #4
Posted 25 July 2012 - 05:48 PM
Do you think you could help me with 1 more thing? My code that is fixed and such is attempting to run. All other functions are working but "if nMenuNum = 1 then…"

function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
  if cEvent == "terminate" then
  end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
return x
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenuTitle)
local nSelection = 0
local bLoop = true

while bLoop do
  term.clear()
  term.setCursorPos(1, 1)
  print(sMenuTitle)
  print()

  for nLine = 0, #mChoices do
   local sLine = "  "
   if nSelection == nLine then
    sLine = "> "
   end
   sLine = sLine .. mChoices[nLine]
   print(sLine)
  end
 
  local nWidth, nHeight = term.getSize()
  local y = nHeight
  local x = getRight("LNET Technologies")
  term.setCursorPos(x, y)
  term.write("LNET Technologies")
 
  local sEvent, nKey = os.pullEvent("key")
 
  if nKey == 200 then
   if mChoices[nSelection - 2] then
    nSelection = nSelection - 2
   end
  elseif nKey == 208 then
   if mChoices[nSelection + 2] then
    nSelection = nSelection + 2
   end
  elseif nKey == 28 then
   if mChoices[nSelection] then
    bLoop = false
    return nSelection
   end
  end
end
end
function menu()
repeat
  if nMenuNum == 0 then
   mChoices = {}
   mActions = {}
   mChoices[0] = "Login"
   mChoices[1] = " "
   if not fs.exists("/LNEX/data/retrieve/passuid") == true then
    mChoices[2] = "Create Account"
    mChoices[3] = " "
    mChoices[4] = "Shutdown"
    mChoices[5] = " "
    mChoices[6] = "Reboot"
    mActions[0] = function()
	 bMenuLoop = false
	 term.clear()
	 shell.run("/LNEX/Client/LNEX")
    end
    mActions[2] = function() nMenuNum = 1 end
    mActions[4] = function()
	 term.clear()
	 os.shutdown()
    end
    mActions[6] = function()
	 term.clear()
	 os.reboot()
    end
    local nSelection = runMenu(mChoices, "LNEX Security Preface")
    mActions[nSelection]()
   else
    mChoices[2] = "Shutdown"
    mChoices[3] = " "
    mChoices[4] = "Reboot"
    mActions[0] = function() shell.run("/LNEX/Client/LNEX") end
    mActions[2] = function()
	 term.clear()
	 os.shutdown()
    end
    mActions[4] = function()
	 term.clear()
	 os.reboot()
    end
    local nSelection = runMenu(mChoices, "LNEX Security Preface")
    mActions[nSelection]()
   end
  elseif nMenuNum == 1 then
    term.clear()
    term.write("Hello")
  end
until bMenuLoop == false
end
sleep(.5)
bMenuLoop = true
nMenuNum = 0
tChoices = {}
tActions = {}
menu()
BigSHinyToys #5
Posted 25 July 2012 - 06:26 PM
Do you think you could help me with 1 more thing? My code that is fixed and such is attempting to run. All other functions are working but "if nMenuNum = 1 then…"
Spoiler

function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
  if cEvent == "terminate" then
  end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
return x
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenuTitle)
local nSelection = 0
local bLoop = true

while bLoop do
  term.clear()
  term.setCursorPos(1, 1)
  print(sMenuTitle)
  print()

  for nLine = 0, #mChoices do
   local sLine = "  "
   if nSelection == nLine then
	sLine = "> "
   end
   sLine = sLine .. mChoices[nLine]
   print(sLine)
  end

  local nWidth, nHeight = term.getSize()
  local y = nHeight
  local x = getRight("LNET Technologies")
  term.setCursorPos(x, y)
  term.write("LNET Technologies")

  local sEvent, nKey = os.pullEvent("key")

  if nKey == 200 then
   if mChoices[nSelection - 2] then
	nSelection = nSelection - 2
   end
  elseif nKey == 208 then
   if mChoices[nSelection + 2] then
	nSelection = nSelection + 2
   end
  elseif nKey == 28 then
   if mChoices[nSelection] then
	bLoop = false
	return nSelection
   end
  end
end
end
function menu()
repeat
  if nMenuNum == 0 then
   mChoices = {}
   mActions = {}
   mChoices[0] = "Login"
   mChoices[1] = " "
   if not fs.exists("/LNEX/data/retrieve/passuid") == true then
	mChoices[2] = "Create Account"
	mChoices[3] = " "
	mChoices[4] = "Shutdown"
	mChoices[5] = " "
	mChoices[6] = "Reboot"
	mActions[0] = function()
	 bMenuLoop = false
	 term.clear()
	 shell.run("/LNEX/Client/LNEX")
	end
	mActions[2] = function() nMenuNum = 1 end
	mActions[4] = function()
	 term.clear()
	 os.shutdown()
	end
	mActions[6] = function()
	 term.clear()
	 os.reboot()
	end
	local nSelection = runMenu(mChoices, "LNEX Security Preface")
	mActions[nSelection]()
   else
	mChoices[2] = "Shutdown"
	mChoices[3] = " "
	mChoices[4] = "Reboot"
	mActions[0] = function() shell.run("/LNEX/Client/LNEX") end
	mActions[2] = function()
	 term.clear()
	 os.shutdown()
	end
	mActions[4] = function()
	 term.clear()
	 os.reboot()
	end
	local nSelection = runMenu(mChoices, "LNEX Security Preface")
	mActions[nSelection]()
   end
  elseif nMenuNum == 1 then
	term.clear()
	term.write("Hello")
  end
until bMenuLoop == false
end
sleep(.5)
bMenuLoop = true
nMenuNum = 0
tChoices = {}
tActions = {}
menu()
It is working But there is no place for it to stop / pause so it errors try this

Spoiler

function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
if cEvent == "terminate" then
end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
return x
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenuTitle)
local nSelection = 0
local bLoop = true

while bLoop do
term.clear()
term.setCursorPos(1, 1)
print(sMenuTitle)
print()

for nLine = 0, #mChoices do
local sLine = " "
if nSelection == nLine then
sLine = "> "
end
sLine = sLine .. mChoices[nLine]
print(sLine)
end

local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")

local sEvent, nKey = os.pullEvent("key")

if nKey == 200 then
if mChoices[nSelection - 2] then
nSelection = nSelection - 2
end
elseif nKey == 208 then
if mChoices[nSelection + 2] then
nSelection = nSelection + 2
end
elseif nKey == 28 then
if mChoices[nSelection] then
bLoop = false
return nSelection
end
end
end
end
function menu()
repeat
if nMenuNum == 0 then
mChoices = {}
mActions = {}
mChoices[0] = "Login"
mChoices[1] = " "
if not fs.exists("/LNEX/data/retrieve/passuid") == true then
mChoices[2] = "Create Account"
mChoices[3] = " "
mChoices[4] = "Shutdown"
mChoices[5] = " "
mChoices[6] = "Reboot"
mActions[0] = function()
bMenuLoop = false
term.clear()
shell.run("/LNEX/Client/LNEX")
end
mActions[2] = function()
nMenuNum = 1
end
mActions[4] = function()
term.clear()
os.shutdown()
end
mActions[6] = function()
term.clear()
os.reboot()
end
local nSelection = runMenu(mChoices, "LNEX Security Preface")
print(nSelection)
os.pullEvent()
mActions[nSelection]()
else
mChoices[2] = "Shutdown"
mChoices[3] = " "
mChoices[4] = "Reboot"
mActions[0] = function()
shell.run("/LNEX/Client/LNEX")
end
mActions[2] = function()
term.clear()
os.shutdown()
end
mActions[4] = function()
term.clear()
os.reboot()
end
local nSelection = runMenu(mChoices, "LNEX Security Preface")
mActions[nSelection]()
end
elseif nMenuNum == 1 then
term.clear()
term.write("Hello")
os.pullEvent() -- this gives it a place to pause
end
until bMenuLoop == false
end
sleep(.5)
bMenuLoop = true
nMenuNum = 0
tChoices = {}
tActions = {}
menu()