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

Problems with OS

Started by Pedro1745, 26 December 2017 - 12:40 AM
Pedro1745 #1
Posted 26 December 2017 - 01:40 AM
Hello, i have a problem, i was trying to use an OS fron a tutorial and i wrote all the code exactly like the video showed but i had an error saying bios:14: [string ]:18: "(" expected
The content of line 18 was term.clear()
I don't know what happened, if someone can help, thanks
Bomb Bloke #2
Posted 26 December 2017 - 04:59 AM
When Lua tells you "something was expected", really it means "something unexpected was found". Odds are you didn't finish line 17 correctly, so it's assuming you intend for line 18 to finish it off.
Luca_S #3
Posted 26 December 2017 - 06:17 AM
Also please post the whole code, it makes it difficult to tell the Problem just by one line.
The problem might also be unrelated to the line you posted because the erroring code is in another file than you think it is.

You can either post your code here in code tags or upload it to pastebin if it's to large.
Pedro1745 #4
Posted 26 December 2017 - 08:53 PM
hello, i have the complete code to show you how it´s done and can you correct errors you found, thanks.
complete code:
Spoiler
os.pullEvent = os.pullEventRaw

local w,h = term.getSize()

function printCentered (y,s)

  local x = math.floor((w - string.len(s)) /2)
  term.setCursorPos(x,y)
  term.clearLine()
  term.write(s)
end

--Draw Menu Function

local nOption = 1

local function drawMenu
  term.clear()
  term.setCursorPos(1,1)
  term.write("Rubik OS 0.1")

  term.setCursorPos(w-11,1)
  if nOption == 1 then
    term.write("Comandos")
  elseif nOption == 2 then
    term.write("Programas")
  elseif nOption == 3 then
    term.write("Apagar")
  elseif nOption == 4 then
    term.write("Desinstalar")
  else
    end
end
--Gui


term.clear()
local function drawFrontend()
  printCentered(math.floor(h/2) - 3, "")
  printCentered(math.floor(h/2) - 2, "Menu Inicio")}
  printCentered(math.floor(h/2) - 1, "")
  printCentered(math.floor(h/2) + 0, ((nOption == 1 and "[ Comandos ]") or "Comandos" )
  printCentered(math.floor(h/2) + 1, ((nOption == 2 and "[ Programas]") or "Programas")
  printCentered(math.floor(h/2) + 2, ((nOption == 3 and "[ Apagar ]") or  "Apagar"
  printCentered(math.floor(h/2) + 3, ((nOption == 4 and "[ Desinstalar "] or "Desinstalar"
end

--Display

drawMenu()
drawFrontend()

while true do
  local e,p = os.pullEvent()
    if e == "key" then
	  local key = p
	  if key == 17 od key == 2000 then
	  
	    if  nOption > 1 then
		  nOption = nOption - 1
		  drawMenu()
		  drawFrontend()
	    end
	  elseif key == 31 or key == 208 then
	    if nOption < 4 then
		  nOption = nOption + 1
		  drawMenu()
		  drawFrontend()
	    end
	  end
   elseif key == 28 then
	  break
   end
end
end
term.clear()

--Conditions
if nOption == 1 then
  shell.run("os/.command"
elseif nOption == 2 then
  shell.run("os/.programs")  
elseif nOption == 3 then
  os.shutdown()
else
  shell.run("os/.uninstall")
end
Edited by
Bomb Bloke #5
Posted 27 December 2017 - 06:34 AM
Line 17 is indeed missing brackets:

local function drawMenu

You also seem to have an excess "end" on line 70.
Dog #6
Posted 27 December 2017 - 06:47 AM
In your while loop (bottom third of your script) you have

if key == 17 od key == 2000 then

I believe you wanted an 'or' instead of 'od'
Luca_S #7
Posted 27 December 2017 - 09:55 AM
In your while loop (bottom third of your script) you have

if key == 17 od key == 2000 then

I believe you wanted an 'or' instead of 'od'
Adding to that 2000 is too high to be a keycode. If you meant the up key it's 200(For better readability I suggest you use keys.up, keys.down, etc. Also if you are looking for keys that also queue a char event you should probably take the char event instead, because then you won't have problems with non-english keyboard layout(With a German keyboard layout it's always frustrating when people check for keys.y instead of the char "y" because I have to press z instead)

Then in the drawmenu function you can omit the else and just put an end there:

  elseif nOption == 4 then
    term.write("Desinstalar")
  else
    end

In line 40 you have an } which is there for no reason:

printCentered(math.floor(h/2) - 2, "Menu Inicio")}

In lines 44 and 45 you are missing two closing brackets:

  printCentered(math.floor(h/2) + 2, ((nOption == 3 and "[ Apagar ]") or  "Apagar"
  printCentered(math.floor(h/2) + 3, ((nOption == 4 and "[ Desinstalar "] or "Desinstalar"
Here in Line 45 you are also putting the ] outside of the string and you are missing the closing bracket after the string

In lines 42 and 43 you are missing 1:

  printCentered(math.floor(h/2) + 0, ((nOption == 1 and "[ Comandos ]") or "Comandos" )
  printCentered(math.floor(h/2) + 1, ((nOption == 2 and "[ Programas]") or "Programas")

You are also missing a closing bracket here:

  shell.run("os/.command"
Pedro1745 #8
Posted 28 December 2017 - 02:27 AM
Thanks to all of you for helping me correcting this, it was written so badly but now doesn´t work because when i run it and says that "end" (line 85) is expected to close line 17 "fuction" any help?
Edited on 28 December 2017 - 03:17 PM
Luca_S #9
Posted 09 January 2018 - 06:31 PM
Thanks to all of you for helping me correcting this, it was written so badly but now doesn´t work because when i run it and says that "end" (line 85) is expected to close line 17 "fuction" any help?

I applied all suggested changes to your code and it works. Can you post your code AFTER you applied these fixes?