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

ERROR Line 38 attempt to call nill Please help

Started by NotSoMuchAGeek, 03 August 2015 - 09:36 AM
NotSoMuchAGeek #1
Posted 03 August 2015 - 11:36 AM
Here is my code, Its The first OS I have made I'm using computer craft version 1.73 on minecraft 1.7.10
I dont know if that matters but anyways please help me try to find my issue


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

local nOption = 1

local function drawMenu()
   term.clear()
   term.setCursorPos(1,1)
   term.write("OS I")
term.setCursorPos(1,2)
shell.run("id")

   term.setCursorPos(w-11,1)
   if nOption == 1 then
   term.write("Command")
elseif nOption == 2 then
   term.write("Programs")
elseif nOption == 3 then
   term.write("Shutdown")
elseif nOption == 4 then
   term.write("Uninstall")
else
end

end

--GUI
term.clear()
local function drawFrontend()
   printCentered( math.floor(h/2) - 3, "")
   printCentered( math.floor(h/2) - 2, "Start Menu" )
   printCentered( math.floor(h/2) - 1, "")
   printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Command  ]") or "Command" )
   printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
   printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
   printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Uninstall]") or " Uninstall" )
   printCentered( math.floor(h/2) + 4, "")
end

--Display
drawMenu()
drawFrontend()

while true do
local e,p = os.pullEvent()
if e == "key" then
  local key = p
  if key == 17 or key == 200 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
elseif key == 28 then
break
end
end
term.clear()

--Conditions
if nOption  == 1 then
shell.run("ios/.command")
elseif nOption == 2 then
shell.run("ios/.programs")
elseif nOption == 3 then
os.shutdown()
else
shell.run("ios/.UninstallDialog")
end
KingofGamesYami #2
Posted 03 August 2015 - 04:02 PM
Is this a copy-paste of your own program? Because when I run the program, I get:


[string "test"]:84: 'end' expected (to close 'while' at line 52) near '<eof>'

Fixing this results in this 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

local nOption = 1

local function drawMenu()
  term.clear()
  term.setCursorPos(1,1)
  term.write("OS I")
  term.setCursorPos(1,2)
  shell.run("id")

  term.setCursorPos(w-11,1)
  if nOption == 1 then
   term.write("Command")
  elseif nOption == 2 then
   term.write("Programs")
  elseif nOption == 3 then
   term.write("Shutdown")
  elseif nOption == 4 then
   term.write("Uninstall")
  else
end

end

--GUI
term.clear()
local function drawFrontend()
   printCentered( math.floor(h/2) - 3, "")
   printCentered( math.floor(h/2) - 2, "Start Menu" )
   printCentered( math.floor(h/2) - 1, "")
   printCentered( math.floor(h/2) + 0, ((nOption == 1) and "[ Command  ]") or "Command" )
   printCentered( math.floor(h/2) + 1, ((nOption == 2) and "[ Programs ]") or "Programs" )
   printCentered( math.floor(h/2) + 2, ((nOption == 3) and "[ Shutdown ]") or "Shutdown" )
   printCentered( math.floor(h/2) + 3, ((nOption == 4) and "[ Uninstall]") or " Uninstall" )
   printCentered( math.floor(h/2) + 4, "")
end

--Display
drawMenu()
drawFrontend()

while true do
  local e,p = os.pullEvent()
  if e == "key" then
    local key = p
    if key == 17 or key == 200 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
    elseif key == 28 then
       break
    end
  end
end
term.clear()
--Conditions
if nOption  == 1 then
  shell.run("ios/.command")
elseif nOption == 2 then
  shell.run("ios/.programs")
elseif nOption == 3 then
  os.shutdown()
else
  shell.run("ios/.UninstallDialog")
end

…which errors when I select anything, because I don't have the programs you're trying to shell.run. I suspect one of the programs could be erroring on line 38, not your OS.</eof>
Edited on 03 August 2015 - 02:03 PM
NotSoMuchAGeek #3
Posted 03 August 2015 - 09:30 PM
yes it is, here is my startup code aswell. it has the shell.run for .menu which is the name of the code i posted above

term.clear()
term.setCursorPos(1,1)
print("OS I")
print("Loading...")
term.setCursorPos(2,3)
sleep(1)
textutils.slowPrint(">>>>>>>>>>>>>")
sleep(1)
shell.run(".menu")
Bomb Bloke #4
Posted 04 August 2015 - 01:41 AM
Yami's telling you to take another look at your error - the computer will also be telling you the filename the bad line is in. That's the file you should be inspecting. The code you've posted so far won't produce that error ("trying to call a function that hasn't been defined") on the 38th line.
NotSoMuchAGeek #5
Posted 04 August 2015 - 06:40 AM
Does it have to on an advanced computer? because earlier i noticed the color is only or advanced monitor
Astrophylite #6
Posted 04 August 2015 - 05:50 PM
Does it have to on an advanced computer? because earlier i noticed the color is only or advanced monitor
If you want to use color, you need to have an advanced computer/monitor, otherwise, it will cause another error :)/>