Posted 13 June 2013 - 10:32 AM
Hello dear programmers!
Today I was working on my GUIbuilder and figured out that my term API overwrite was not working as I was expecting.
I came to the conclusion, that a table doesnt get created. The program is starting to complain at line 69, Im assuming it will also error on lines 70 and 71.
I create the table via a metatable, wich you can see on line 16. I immediatly create the table, and that does work (It is not starting to complain). But when I call line 69, it says: "attempt to call nil"
I had this error for quite a few days now, and I cant seem to figure out the problem. Also, the file.writeLine's are for debugging.
For those who like to count:
Or if you dont feel like counting: http://pastebin.com/hzQfHndT
Thank you very much in advance!
Today I was working on my GUIbuilder and figured out that my term API overwrite was not working as I was expecting.
I came to the conclusion, that a table doesnt get created. The program is starting to complain at line 69, Im assuming it will also error on lines 70 and 71.
I create the table via a metatable, wich you can see on line 16. I immediatly create the table, and that does work (It is not starting to complain). But when I call line 69, it says: "attempt to call nil"
I had this error for quite a few days now, and I cant seem to figure out the problem. Also, the file.writeLine's are for debugging.
For those who like to count:
Spoiler
-- Load layering system with screen system
local layer = {
currLayer = 1;
layers = 0;
}
local screen = {}
setmetatable( screen, {
__call = function()
layer[#layer + 1] = {}
for word in tostring( objects ):gmatch("[^%s]+") do
layer[#layer][word] = {}
end
layer.layers = layer.layers + 1
screen[layer.layers] = {}
for x = 1, w do
for y = 1, h do
screen[layer.layers][x] = {}
screen[layer.layers][x][y] = {}
screen[layer.layers][x][y]["background"] = 32768
screen[layer.layers][x][y]["text"] = 1
screen[layer.layers][x][y]["char"] = " "
end
end;
end
})
screen()
-- Screen tracking, partial overwrite term API
local backgroundColour = colours.black
local textColour = colours.white
if not term.native then
term.native = {}
term.native.setBackgroundColour = term.setBackgroundColour
term.native.setTextColour = term.setTextColour
term.native.write = term.write
end
local tbackground = term.setBackgroundColour
local ttext = term.setTextColour
local twrite = term.write
term.setBackgroundColour = function( col )
term.native.setBackgroundColour( col )
backgroundColour = col
end
term.setTextColour = function( col )
term.native.setTextColour( col )
textColour = col
end
term.write = function( s )
if type( s ) ~= "string" then error("term.write no string", 2) end
local x, y = term.getCursorPos()
pcall( fs.delete, "error.txt" )
local file = fs.open( "error.txt", "a")
for i = 0, ( s:len() > w - x - 1 and w - x - 1 or s:len() ) - 1 do
--[[screen[layer.currLayer][x + i][y].char = s:sub( i+1, i+1 )
screen[layer.currLayer][x + i][y].text = textColour
screen[layer.currLayer][x + i][y].background = backgroundColour]]
file.writeLine( i..": LAYER "..layer.currLayer.." X "..x + i.." Y "..y)
file.writeLine( tostring(screen[layer.currLayer]) )
file.writeLine( tostring(screen[layer.currLayer][x + i]) )
file.writeLine( tostring(screen[layer.currLayer][x + i][y]) )
file.writeLine( tostring(screen[layer.currLayer][x + i][y]["background"]) )
file.writeLine( tostring(screen[layer.currLayer][x + i][y]["char"]) )
file.writeLine( tostring(screen[layer.currLayer][x + i][y]["text"]) )
file.writeLine( "\n" )
end
file.close()
term.native.write( s )
end
Or if you dont feel like counting: http://pastebin.com/hzQfHndT
Thank you very much in advance!