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

Creating an Ink-based program-creator.. Help

Started by Goof, 30 March 2014 - 05:03 PM
Goof #1
Posted 30 March 2014 - 07:03 PM
Hello everyone!

Im trying to make an unofficial Ink-based program-creator program, but im quite stuck in making headerMenus…

The first menu does never show up?

Picture:

Picture info: There should be a button called "Edit" just before the "View" button… but it seems like its not even creating that? nothing happens when i click on the "edit" invisible button's position, but it works with the "View", "Project" etc…

CODE ( line 34 to 72 and 259 to 290 )

Thanks in Advance
Edited on 30 March 2014 - 05:03 PM
CometWolf #2
Posted 30 March 2014 - 07:41 PM
My that is a messy setup you have there, you're gonna have to do some debugging yourself. Here's the funcftion i use to debug variables

debug = {
  times = 0,
  prep = function()
    screen:setBackgroundColor(colors.black)
    screen:setTextColor(colors.white)
    screen:setLayer(6)
    screen:fill()
    screen:setCursorPos(1,1)
  end,
  pause = function()
    while true do
	  local _e,key = os.pullEvent"key"
	  if key == 14 then
	    error()
	  else
	    return
	  end
    end
  end,
  variables = function(...)
    debug.times = debug.times+1
    local tLines = {}
    for i=1,#arg do
	  local var = arg[i]
	  if not var then
	    tLines[#tLines+1] = "nil"
	  elseif type(var) == "table" then
	    for k,v in pairs(var) do
		  tLines[#tLines+1] = k..": "..tostring(v)
	    end
	  else
	    tLines[#tLines+1] = type(var).." "..var
	  end
    end
    local lines = tTerm.screen.y-2
    local pages = math.ceil(#tLines/lines)
    for page = 1,pages do
	  debug.prep()
	  print("Page "..page.."/"..pages.." Debug call #"..debug.times.." on "..tFile.program)
	  for line = lines*(page-1)+1,lines*page do
	    if not tLines[line] then
		  break
	    else
		  print(tLines[line])
	    end
	  end
	  debug.pause()
    end
  end,
}
I'd suggest using it to check the variables determining where the text is loacted. See if any of them are incorrect, then check where they're generated.

	  v["position"] = {}
	  v["position"]["xPos"] = xText;
	  v["position"]["xMin"] = xStart;
	  v["position"]["xMax"] = xEnd;
	  v["position"]["yMin"] = yMin;
	  v["position"]["yMax"] = yMax;
	  debug.variables(v.position)
Goof #3
Posted 30 March 2014 - 07:44 PM
Well i can only say that something in that debugging code is wrong… thers attempt to index'es ( a nil value ) several times… woo?

Is this debug-program used in something else with custom term etc?
CometWolf #4
Posted 30 March 2014 - 07:46 PM
oh right, my bad :P/>

debug = {
  times = 0,
  prep = function()
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.white)
    term.clear()
    term.setCursorPos(1,1)
  end,
  pause = function()
    while true do
		  local _e,key = os.pullEvent"key"
		  if key == 14 then
		    error()
		  else
		    return
		  end
    end
  end,
  variables = function(...)
    debug.times = debug.times+1
    local tLines = {}
    for i=1,#arg do
		  local var = arg[i]
		  if not var then
		    tLines[#tLines+1] = "nil"
		  elseif type(var) == "table" then
		    for k,v in pairs(var) do
				  tLines[#tLines+1] = k..": "..tostring(v)
		    end
		  else
		    tLines[#tLines+1] = type(var).." "..var
		  end
    end
    local lines = tTerm.screen.y-2
    local pages = math.ceil(#tLines/lines)
    for page = 1,pages do
		  debug.prep()
		  print("Page "..page.."/"..pages.." Debug call #"..debug.times.." on "..tFile.program)
		  for line = lines*(page-1)+1,lines*page do
		    if not tLines[line] then
				  break
		    else
				  print(tLines[line])
		    end
		  end
		  debug.pause()
    end
  end,
}
There, try that
Goof #5
Posted 30 March 2014 - 07:52 PM
tTerm.screen.y-2 is making everything error…
Spoiler

debug = {
  times = 0,
  prep = function()
    term.setBackgroundColor(colors.black)
    term.setTextColor(colors.white)
    term.clear()
    term.setCursorPos(1,1)
  end,
  pause = function()
    while true do
      local _e,key = os.pullEvent"key"
      if key == 14 then
        error()
      else
        return
      end
    end
  end,
  variables = function(...)
    debug.times = debug.times+1
    local tLines = {}
    for i=1,#arg do
      local var = arg[i]
      if not var then
        tLines[#tLines+1] = "nil"
      elseif type(var) == "table" then
        for k,v in pairs(var) do
          tLines[#tLines+1] = k..": "..tostring(v)
        end
      else
        tLines[#tLines+1] = type(var).." "..var
      end
    end
    local lines = tTerm.screen.y-2
    local pages = math.ceil(#tLines/lines)
    for page = 1,pages do
      debug.prep()
      print("Page "..page.."/"..pages.." Debug call #"..debug.times.." on "..tFile.program)
      for line = lines*(page-1)+1,lines*page do
        if not tLines[line] then
          break
        else
          print(tLines[line])
        end
      end
    debug.pause()
    end
  end,
}

startup:43: attempt to index ( a nil value! )
CometWolf #6
Posted 30 March 2014 - 07:54 PM
Guess i should get around to throwing this stuff in a standalone api at some point, it's proven quite handy lol.
just change it to 17, it's the size of the screen on the y-axis.
Goof #7
Posted 30 March 2014 - 07:56 PM
xD… now theres an error online 47
print("Page "..page.."/"..pages.." Debug call #"..debug.times.." on "..tFile.program) – what is tFile.program?
Same type of error. (attempt to index)


EDIT: Im going to make a quick debug test… then ill respond

EDIT 2:
Well after some debugging, i found out that i wasn't setting the cursor position at the beginning so everything went to place the
text/button -1 to the comparrison of the table,
which makes the first button invisible.
so End result so far:
CODE
Edited on 30 March 2014 - 06:08 PM
CometWolf #8
Posted 30 March 2014 - 08:07 PM
It's not really important, it's the path of the program. You can change it to shell.getRunningProgram()