Posted 06 March 2014 - 05:26 AM
I have very little experience with LUA programming language so when you read this it gives a brief overview on me.
Code that I have written so far:
The problems I have been having are:
The information button outputs an error message: ButtonAPI:50: attempt to index ? (a nill value)
When computer is turned on it is a blank screen until one button is clicked (not including the title)
Code that I have written so far:
Spoiler
Main Program (startup)
local mon = peripheral.wrap("top")
mon.setTextScale(1)
function Title(text)
mon.setTextColor(colors.red)
w, h = mon.getSize()
mon.setCursorPos((w-#text)/2+1, 1)
mon.write(text)
end
function Buttons()
os.loadAPI("ButtonAPI")
mon = peripheral.wrap("top")
function FillTable()
ButtonAPI.setTable("Rules", Rules, 10, 14, 6, 6)
ButtonAPI.setTable("Infomation", Info, 10, 19, 8, 8)
ButtonAPI.setTable("Plugins", Plugins, 9, 17, 10, 10)
ButtonAPI.setTable("How to get started", Htgs, 9, 28, 12, 12)
end
function GetClick()
event, side, x, y = os.pullEvent("monitor_touch")
ButtonAPI.checkxy(x, y)
end
function Rules()
ButtonAPI.flash("Rules")
print("Rules")
end
function Info()
ButtonAPI.flash("Information")
print("Information")
end
function Plugins()
ButtonAPI.flash("Plugins")
print("Plugins")
end
function Htgs()
ButtonAPI.flash("How to get started")
print("How to get started")
end
FillTable()
while true do
GetClick()
end
end
Title("bblewittAG's Server")
Buttons()
Button API (API)
local mon = peripheral.wrap("top")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.black)
function setTable(name, func, xmin, xmax, ymin, ymax)
button[name] = {}
button[name]["func"] = func
button[name]["active"] = false
button[name]["xmin"] = xmin
button[name]["ymin"] = ymin
button[name]["xmax"] = xmax
button[name]["ymax"] = ymax
end
function fill(text, color, bData)
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - #text) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - #text +1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name,data in pairs(button) do
local on = data["active"]
if on == true then currColor = colors.black else currColor = colors.black end
fill(name, currColor, data)
end
end
function toggleButton(name)
button[name]["active"] = not button[name]["active"]
screen()
end
function flash(name)
toggleButton(name)
screen()
sleep(0.15)
toggleButton(name)
screen()
end
function checkxy(x, y)
for name, data in pairs(button) do
if y>=data["ymin"] and y <= data["ymax"] then
if x>=data["xmin"] and x<= data["xmax"] then
data["func"]()
return true
end
end
end
return false
end
The information button outputs an error message: ButtonAPI:50: attempt to index ? (a nill value)
When computer is turned on it is a blank screen until one button is clicked (not including the title)