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

window:233: bad argument: double expected, got nil

Started by TheRockettek, 02 November 2016 - 08:43 AM
TheRockettek #1
Posted 02 November 2016 - 09:43 AM
I am looking at my code on why its not working and i am blind X_X

term.clear()
xy,tc,bc = term.setCursorPos(),term.setTextColour(),term.setBackgroundColour()
local cut = function(t,l)
if string.len(t) > l then
  return string.sub(t,1,l)
else
  return t
end
end
local draw = function()
res = {term.getSize()}
paintutils.drawFilledBox(1,1,res[1],res[2],colours.white)
paintutils.drawFilledBox(1,1,res[1],3,colours.cyan)
xy(2,2)
bc(colours.cyan)
if path == "/" then
  tc(colours.lightGrey)
else
  tc(colours.white)
end
term.write("<")
xy(4,2)
tc(colours.white)
term.write(cut(path,res[1]-4))
end
while true do
if not path then path = "/" end
local offset = 0
local y = 4
local fileList = fs.list(path)
draw()
if #fileList > res[2]-3 then
  local len = res[2]-3
else
  local len = #fileList
end
for i=1,len,1 do
  local filePath = fs.combine(path,fileList[i+offset])
  if fs.isDir(filePath) then
   paintutils.drawFilledBox(1,y,1,y,colours.blue)
  elseif fs.isReadOnly(filePath) then
   paintutils.drawFilledBox(1,y,1,y,colours.red)
  else
   paintutils.drawFilledBox(1,y,1,y,colours.yellow)
  end
  xy(3,y)
  tc(colours.grey)
  bc(colours.white)
  term.write(fileList[i+offset])
  y=y+1
end
local e,c,a,b = os.pullEvent()
if e == "mouse_up" then -- click
  if c == 1 then
  -- leftclick
  elseif c == 2 then
   local offset = 0
  elseif c == 3 then
  -- rightclick
  end
elseif e == "mouse_scroll" then -- scroll
  if a == "-1" and offset > 0 then
   local offset = offset - 1
  elseif a == "1" and offset < #fileList then
   local offset = offset + 1
  end
end
end
Edited on 02 November 2016 - 10:19 AM
KingofGamesYami #2
Posted 02 November 2016 - 11:11 AM
You should not be calling functions while you attempt to assign them to variables.

Edit: Bomb Bloke is blind today, x is most definitely nil on the second line of your program.
Edited on 02 November 2016 - 10:13 AM
Bomb Bloke #3
Posted 02 November 2016 - 11:11 AM
Line 233 falls inside the setCursorPos function (assuming your CC install is at least somewhat up-to-date), and is checking the x value specifically. Nowhere in the code you've provided would the x value possibly be nil - double check that this is the code you're actually running on your computer, and that this is all of the code involved.

*headdesk* Yami has better eyes than I do.
Edited on 02 November 2016 - 10:13 AM
TheRockettek #4
Posted 02 November 2016 - 11:19 AM
Just needed to change

xy,tc,bc = term.setCursorPos(),term.setTextColour(),term.setBackgroundColour()

into

xy,tc,bc = term.setCursorPos,term.setTextColour,term.setBackgroundColour