Jump to content




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


2 replies to this topic

#1 UP844

  • Members
  • 21 posts

Posted 14 October 2015 - 04: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()



#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 14 October 2015 - 04:52 AM

        options = {"ex1", "ex2", "quit"}

This line should end with a comma.

#3 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 14 October 2015 - 09: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users