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

shell.run attemt to call nil

Started by makerimages, 09 December 2012 - 08:27 AM
makerimages #1
Posted 09 December 2012 - 09:27 AM
why does this function:


function ProgramLable()
term.setCursorPos(21,18)
term.setBackgroundColor(colors.yellow)
print("PROGRAMS")
term.setBackgroundColor(colors.lightBlue)
event, p1, p2, p3 = os.pullEvent(mouse_click)
if p2==21 and p3==18 then
shell.run("programs/programMenu")
end
end

errors that the shell.run line errors attemt to index ? a nil value

?????
Kingdaro #2
Posted 09 December 2012 - 09:28 AM
It might be a problem with the program it's running. Post the text of the programMenu program.
makerimages #3
Posted 09 December 2012 - 09:31 AM

---[[Copyright Makerimages, all of the code here was made or adapted by Makerimages and you may not distribute this code without prior written premission from Makerimages]]---
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
    write(' ')
  end
end
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(10,1)
print("Programs you have installed")

is the internals of the programMenu
AndreWalia #4
Posted 09 December 2012 - 09:45 AM

---[[Copyright Makerimages, all of the code here was made or adapted by Makerimages and you may not distribute this code without prior written premission from Makerimages]]---
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightBlue)
term.clear()
term.setBackgroundColor(colors.yellow)
local width=4
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1] do
	write(' ')
  end
end
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(10,1)
print("Programs you have installed")

is the internals of the programMenu
instead of

local size={term.getSize()}
try

local sizeX,sizeY = term.getCursorPos()
local size={sizeX,sizeY}


local sizeX,sizeY = term.getSize()
local size={sizeX,sizeY}
It should work, though i haven't tested it
Kingdaro #5
Posted 09 December 2012 - 09:47 AM
There doesn't seem to be any problem - I ran both scripts and they worked fine.

instead of

local size={term.getSize()}
try

local sizeX,sizeY = term.getCursorPos()
local size={sizeX,sizeY}
It should work, though i haven't tested it
What he did is valid though.
makerimages #6
Posted 09 December 2012 - 10:01 AM
hmmm, still no work
MemoryLeak21 #7
Posted 09 December 2012 - 02:24 PM
You need to put mouse_click in quotation marks:


event, p1, p2, p3 = os.pullEvent("mouse_click")

Otherwise Lua thinks you're addressing a variable called mouse_click, which wasn't declared beforehand.
MysticT #8
Posted 09 December 2012 - 02:53 PM
If the function is inside an api, you can't use the shell api, so that's why it says "attempt to index a nil value" (shell doesn't exist).
makerimages #9
Posted 09 December 2012 - 09:20 PM
that was it, thanks now it works