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

bios:338 [string "menus"]:41: '}' expected (to close '{' at line 39)

Started by UP844, 14 October 2015 - 03:36 AM
UP844 #1
Posted 14 October 2015 - 05:36 AM
I'm just getting back into Computercraft after messing around with basic stuff a few years ago, and I'm getting the error message bios:338 [string "menus"]:41: '}' expected (to close '{' at line 39) from the program below.

Two things to note, I am running Minecraft 1.4.7 (an older version works better for me for various reasons), however I don't think that makes a difference in this case.

Also, I did change a few things around in the code before posting this, and I get the same error message but with different line numbers (It's still the same lines of code, just at a different line number). I added a note in there where the error is supposed to be.

Any help would be greatly appreciated.



local w,h = term.getSize()
local select = 1


local function printCentered(str, ypos)
term.setCursorPos(w/2 - #str/2, ypos)
term.write(str)
end

local function printRight(str, ypos)
term.setCursorPos(w - #str, ypos)
term.write(str)
end

--Functions--

function drawMain()
  printCentered("Picture 1", 8)
  printCentered("Picture 2", 12)
  printCentered("Quit", h-2)
  local ypos = 9
  if select == 2 then ypos = 13
  elseif select == 3 then ypos = h-1 end
  printCentered("---------", ypos)
end  

function drawHeader()
  printCentered("TEST MENU", 1)
  printCentered(string.rep("-", w), 2)
  printRight("qwryzu", h)
end

--Application--

local menustate = "main"

--I THINK IT'S PROBABLY AN ISSUE WITH THIS TABLE--

local mopt = {
  ["main"] = {
	options = {"ex1", "ex2", "quit"}
	draw = drawMain
  }
}


function runMenu()
  while true do
	term.clear()
	drawHeader()
	mopt[menustate].draw()

	local id, key = os.pullEvent("key")
	--UP = 200, DOWN = 208, ENTER = 28

	if key == 200 and select > 1 then select = select-1
	elseif key == 208 and select < #mopt[menustate].options then select = select+1
	elseif key == 28 then
	  if mopt[menustate].options[select] == "quit" then
		break
	  end  
	  menustate = mopt[menustate].options[select]
	end
  end  
end

runMenu()

Bomb Bloke #2
Posted 14 October 2015 - 05:52 AM
        options = {"ex1", "ex2", "quit"}

This line should end with a comma.
Creator #3
Posted 14 October 2015 - 10:31 AM
That is because the elements in a table should be separated with a comma, even if the one of the elements is a table itself.