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

API loading code not working properly ( not working at all)

Started by Creator, 10 March 2015 - 03:29 PM
Creator #1
Posted 10 March 2015 - 04:29 PM
Hi guys,

I am writing an OS and the GUI api, which I called Interact (bam, copyright, don't worry, when it is ready everybody will benefit from it) is not working correctly.

API
--[[
Interact API in ComputerCraft
by Creator
Complete rewrite in OOP
]]--

--Load Function--
function Initialize()
local toReturn = {}
toReturn.Button = {}
toReturn.Button = Button
toReturn.test = {"hi"}
return toReturn
end
--Class Button--
local Button = {
--Button initialization function
new = function(_name,_label,_xPos,_yPos,_xLength,_yLength,_fgColor,_bgColor,_returnValue)
  local self = {}
  setmetatable(self,{__index = Button})
  self.name = _name
  self.label = _label
  self.xPos = _xPos
  self.yPos = _yPos
  self.fgColor = _fgColor
  self.bgColor = _bgColor
  self.xLength = _xLength
  self.yLength = _yLength
  self.returnValue = _returnValue
  return self
end,
--Draw function
draw = function(self)
  --term.setBackgroundColor(self.bgColor)
  paintutils.drawFilledBox(self.xPos,self.yPos,self.xLength-1,self.yLength-1,self.bgColor)
end
}


Program That Calls The API

--[[
Desktop in ComputerCraft
by Creator
for TheOS
]]--
local textutilsserialize = textutils.serialize
local textutilsunserialize = textutils.unserialize
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.setCursorPos(1,1)
term.clear()
local gui = {}
gui = Interact.Initialize()
print("loading complete")
for i,v in pairs(gui) do
print(i)
print(v)
end
sleep(10)
test = gui.Button.new("test","even",1,1,5,5,colors.red,colors.blue,"my")

The whole is part of an OS you can find here on github.

Thanks a lot guys.

~Creator
Edited on 10 March 2015 - 04:22 PM
Lupus590 #2
Posted 10 March 2015 - 04:50 PM
could you use code tags please (you may want to reindent too

will edit with help when i get this into notepad++

you have a } at the end of your api - it's not meant to be there forgot about the big table

also, not many people use OOP in lua, so your help may be limited

that's all I've got I got nothing
Edited on 10 March 2015 - 04:43 PM
Creator #3
Posted 10 March 2015 - 05:03 PM
Indentation does not really work in CC forums. The } is meant to be there because the functions are located in the Button table. Check github for good indentation.
Edited on 10 March 2015 - 04:05 PM
Lupus590 #4
Posted 10 March 2015 - 05:10 PM
which is why i suggested code tags
[code]remove the dot here->[./code]

also, when you say "it's not working correctly" exactly what is the expected behaviour and what is it doing?
Edited on 10 March 2015 - 04:12 PM
KingofGamesYami #5
Posted 10 March 2015 - 05:21 PM
I don't see any usage of OO here, other than a weird bit where you use setmetatable.

I mean, every button contains a function for creating a new button, and a function for drawing itself.

Also: what errors are you getting, if any? You never told your API to draw anything, so I would assume nothing happens when you run that?
Creator #6
Posted 10 March 2015 - 05:22 PM
oh my error. totally forgot. thanks ;)/>
Creator #7
Posted 10 March 2015 - 06:57 PM
The OOP comes after, when you use the program. The error was that I declared Button agian after the Initialize function. Thanks anyway.