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

[Lua][Debugging] I need help debugging!

Started by jadelade, 21 March 2013 - 04:15 PM
jadelade #1
Posted 21 March 2013 - 05:15 PM
Hi,
i have been working on this file program and its been giving me this weird bug that I can't track down. I feel I may have added a return in some where. every D.write() writes to a monitor to help me debug FYI. if I clicked on a file i should get :1:1.1:22:1.1:1: but insted I got :1:1.1:2 meaning the problem MAY be between line 50 and line 53, if that help you understand my debugging system.
PS: I'm sorry for the bad variable names and stuff i planed on making this just a quick program and I don't have time to add quotes. Sorry!



local w,h = term.getSize()
local files = {}
local dir = {"/"}
local mun = {}
local sDir = ""
local D = peripheral.wrap("monitor_6")

local function drawGUIFiles(loco)
  term.setTextColor(colors.black)
  term.setBackgroundColor(colors.white)
  term.clear()
  term.setCursorPos(1,1)
  term.setBackgroundColor( colors.lightGray )
  term.clearLine()
  write(loco.."/")
  term.setCursorPos(w-1,1)
  term.setBackgroundColor(colors.yellow)
  write("^")
  term.setBackgroundColor(colors.red)
  print("x")
  term.setBackgroundColor(colors.white)

  files = fs.list(loco)
  for i=1,#files do
	if not fs.isDir(loco.."/"..files[i]) then
	  term.setTextColor(colors.red)
	end
	print(files[i])
	term.setTextColor(colors.black)
  end
  term.setCursorPos(0,0)
end

local function combine(comInput)
  local ret = ""
  for i=1,#input do
	comOutput = comOutput..comInput[i]
  end
  return ret
end

local function main()
  while true do
	D.write(":1")
	XXX,botton,x,y = os.pullEvent("mouse_click")
	D.write(":1.1")
	if fs.isDir(files[y-1]) then
	  D.write(":2")
	  table.insert(dir,files[y-1])
	  sDir = combine(dir)
	  drawGUIFiles(sDir)
	  D.write("2:")
	elseif y == 1 and x == w-1 then
	  D.write(":3")
	  if #dir ~= 1 then
		D.write(":3.1")
		table.delete(dir,#dir)
		sDir = combine(dir)
		drawGUIFiles(sDir)
		D.write("3.1:")
	  end
	  D.write("3:")
	elseif y == 1 and x == w then
	  D.write(":4")
	  term.setBackgroundColor(colors.black)
	  term.clear()
	  D.write("4:")
	end
	D.write("1.1:1:")
  end
end

drawGUIFiles(sDir)
main()


Thanks for you help!
GravityScore #2
Posted 22 March 2013 - 12:09 AM


local function combine(comInput)
  local ret = ""
  for i=1,#input do
		comOutput = comOutput..comInput[i]
  end
  return ret
end

Shouldn't comOutput = comOutput .. comInput be ret = ret .. comInput? AND shouldn't #input be #comInput? This would mean that combine is erroring with attempt to get length of nil, or something like that. I assume comOutput is meant to be ret because comOutput hasn't been defined elsewhere, nor has input.
jadelade #3
Posted 22 March 2013 - 02:36 AM
I changed that??? I must of not saved or somthing. That fixes the problem with clicking on a file but if you run the program and click enywere else the program stops.