Posted 21 February 2015 - 08:07 PM
Okay, so I was working on a graphics utility API, and it threw this error. Could you help me clear up what's happening that I've done wrong?
The API code:
The program calling the API code:
Thanks,
- Sam
The API code:
Spoiler
sCols = {
a = colors.white,
b = colors.black,
c = colors.red,
d = colors.blue,
e = colors.gray,
f = colors.lightGray,
g = colors.brown,
h = colors.purple,
i = colors.orange,
j = colors.green,
k = colors.yellow,
l = colors.lightBlue,
m = colors.lime,
n = colors.magenta,
o = colors.pink,
}
function findCol(color)
for k, v in pairs(sCols) do
if v == color then
fCol = k
end
end
return fCol
end
function drawLine(xS, yS, xF, yF, colour)
loadScreens()
if srcs.loaded ~= nil then
for sY=yS, yF do
for start=xS, xF do
srcs[srcs.loaded][sY][xS] = findCol(colour)
end
end
else
local rTbl = {
false,
7,
}
return rTbl
end
end
function clearScreens()
srcs = "{loaded = nil}"
saveScreens()
end
local function saveScreens()
if dirLoadSet == nil then
local h = fs.open("gData/screens","w")
h.write(srcs)
h.close()
else
local h = fs.open(dirLoadSet.."/screens","w")
h.write(srcs)
h.close()
end
end
local function loadScreens()
if dirLoadSet == nil then
if not fs.exists("gData") then
fs.makeDir("gData")
local h = fs.open("gData/screens","w")
h.write("loaded = nil")
h.close()
end
local h = fs.open("gData/screens","r")
scrs = textutils.unserialize(h.readAll())
h.close()
else
local h = fs.open(dirLoadSet.."/screens","r")
end
end
function setFocus(name)
loadScreens()
srcs.loaded = name
saveScreens()
end
function resizeWindow(name, newW, newH)
end
function drawScreen(name, x, y)
if name ~= "loaded" then
loadScreens()
if scrs.loaded then
if scrs[name] ~= nil then
for hi=1, #scrs[name] do
for wi=1, #scrs[name][hi] do
for i=1, #scrs[name][hi][wi] do
local char = string.sub(scrs[name][hi][wi], i, i)
if i==1 then
paintutils.drawPixel((wi+x)-1,(hi+y)-1,sCols[char])
elseif i==2 then
term.setTextColor(sCols[char])
elseif i==3 then
term.setCursorPos((wi+x)-1,(hi+y)-1)
write(char)
end
end
end
end
local rTbl = {
true,
name,
}
return rTbl
end
else
local rTbl = {
false,
4,
}
return rTbl
end
else
local rTbl = {
false,
2,
}
return rTbl
end
end
function newScreen(name, width, height)
loadScreens()
if name ~= "loaded" then
scrs[name] = {}
for h=1, height do
scrs[name][h] = {}
for w=1, width do
scrs[name][h][w] = "abc"
end
end
saveScreens()
local rTbl = {
true,
name,
}
return rTbl
else
local rTbl = {
false,
1,
}
return rTbl
end
end
The program calling the API code:
Spoiler
os.loadAPI("gAPI")
gAPI.newScreen("firstScreen",10,10)
gAPI.drawScreen(1,1)
Thanks,
- Sam