Posted 06 April 2018 - 05:31 PM
So, I'm creating an OS. I would LOVE to have the GUI drawing and stuff in a separate and object-oriented API, so I started working on that. When I coded the button object in the API, I try to draw a button through my bootloader, and it gives me this error: "loader.lua:4: attempt to index ? (a nil value)". This doesn't make sense, even after double-checking my code… It even seems to load the API just fine!
Program in which the API is used:
API:
Used tutorial: http://www.computercraft.info/forums2/index.php?/topic/14938-simple-object-oriented-programming/
Program in which the API is used:
term.clear()
term.setCursorPos(1, 1)
os.loadAPI("DoorOS/apis/GUI/GUI.api")
local btn1 = GUI.button:new()
btn1:draw()
API:
button = {
bkgColor = colors.blue,
text = "Text",
w = 6,
h = 3,
textx = 2,
texty = 2,
x = 2,
y = 2,
new = function(self)
local new = {}
setmetatable(new, {__index = self})
return new
end,
draw = function(self)
term.setCursorPos(x, y)
term.setBackgroundColor(self.bkgColor)
for i=1, self.w do
for i=1, self.h do
term.write(" ")
term.setCursorPos(self.x + i, self.y)
end
term.setCursorPos(self.x, self.y + 1)
end
term.setCursorPos(self.x + 2, self.y + 2)
term.write(self.text)
end,
cock = function(self)
print("Test")
end
}
Used tutorial: http://www.computercraft.info/forums2/index.php?/topic/14938-simple-object-oriented-programming/