Posted 15 April 2014 - 09:33 PM
Hey all,
I am a lua newbie. I borrowed from a piece of code posted here and have changed it slightly to create what I need. I had it working flawlessly, but ran into some error, and had to break the computer it was stored in, reseting everything before I could offload it. So, I rewrote everything in pastebin, and now I cannot get it working.
I apologize if my code is primitive, I am very very new to writing / reading code, but it is rather intuitive so far, with a few exceptions, this obviously being one.
I did trouble shoot as best I know how, going through one at a time and deleting each color.x & it will throw the error until just color.white is left. I did not test if there is just an issue with colors.orange or not, but do not see why there would be. I also tried adding, and removing spaces between each 'element' of the line but that did not fix anything.
Any help would be greatly appreciated.
Here is the code, and the error is thrown in line 103:
I am a lua newbie. I borrowed from a piece of code posted here and have changed it slightly to create what I need. I had it working flawlessly, but ran into some error, and had to break the computer it was stored in, reseting everything before I could offload it. So, I rewrote everything in pastebin, and now I cannot get it working.
I apologize if my code is primitive, I am very very new to writing / reading code, but it is rather intuitive so far, with a few exceptions, this obviously being one.
I did trouble shoot as best I know how, going through one at a time and deleting each color.x & it will throw the error until just color.white is left. I did not test if there is just an issue with colors.orange or not, but do not see why there would be. I also tried adding, and removing spaces between each 'element' of the line but that did not fix anything.
Any help would be greatly appreciated.
Here is the code, and the error is thrown in line 103:
--Look throughout the code for comments like this. They explain what to do to change things.
--What side the monitor will be on (change this if needed)
side = "top"
m = peripheral.wrap(side)
--button on/off color
bactive = colors.cyan
binactive=colors.gray
--text on/off color
tactive=colors.white
tinactive=colors.black
--Background color
bgcolor = colors.black
buttons = {}
function newButton(id,xmin,xmax,ymin,ymax,text,func)
buttons[id] = {}
buttons[id]["xmin"] = xmin
buttons[id]["xmax"] = xmax
buttons[id]["ymin"] = ymin
buttons[id]["ymax"] = ymax
buttons[id]["active"] = false
buttons[id]["text"] = text
buttons[id]["func"] = func
end
---------------------------------------------------------------------------------
function printButton(id)
ymin = buttons[id]["ymin"]
ymax = buttons[id]["ymax"]
xmin = buttons[id]["xmin"]
xmax = buttons[id]["xmax"]
text = buttons[id]["text"]
ia = buttons[id]["active"]
width = xmax - xmin
height = ymax - ymin
if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
for j = ymin,ymax do
m.setCursorPos(xmin,j)
for i = xmin,xmax do
m.write(" ")
end
end
m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
m.write(text)
m.setBackgroundColor(bgcolor)
end
----------------------------------------------------------------------------------
function refreshButtons()
for i = 1,#buttons do
printButton(i)
end
end
function checkxy( x,y )
for i = 1, #buttons do
if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
buttons[i]["active"] = not buttons[i]["active"]
clicked = i
if buttons[i]["func"] ~= nil then
buttons[i]["func"]()
end
end
end
end
end
bool1 = false
bool2 = false
bool3 = false
bool4 = false
bool5 = false
bool6 = false
bool7 = false
rs.setBundledOutput("back",current+colors.white,colors.orange,colors.magenta,colors.yellow,colors.red,colors.lime,colors.lightBlue)
--White is essnce, Orange is blaze, magenta is wither, ghast is yellow, ender is red, passive mobs are lime, wisps are light blue
function xp()
current = rs.getBundledOutput("back")
bool1 = not bool1
if bool1 then
rs.setBundledOutput("back",current-colors.white)
else
rs.setBundledOutput("back",current+colors.white)
end
end
function blaze()
current = rs.getBundledOutput("back")
bool2 = not bool2
if bool2 then
rs.setBundledOutput("back",current-colors.orange)
else
rs.setBundledOutput("back",current+colors.orange)
end
end
function wither()
current = rs.getBundledOutput("back")
bool3 = not bool3
if bool3 then
rs.setBundledOutput("back",current-colors.magenta)
else
rs.setBundledOutput("back",current+colors.magenta)
end
end
function ghast()
current = rs.getBundledOutput("back")
bool4 = not bool4
if bool4 then
rs.setBundledOutput("back",current-colors.yellow)
else
rs.setBundledOutput("back",current+colors.yellow)
end
end
function ender()
current = rs.getBundledOutput("back")
bool5 = not bool5
if bool5 then
rs.setBundledOutput("back",current+colors.red)
else
rs.setBundledOutput("back",current-colors.red)
end
end
function passive()
current = rs.getBundledOutput("back")
bool6 = not bool6
if bool6 then
rs.setBundledOutput("back",current+colors.lime)
else
rs.setBundledOutput("back",current-colors.lime)
end
end
function wisp()
current = rs.getBundledOutput("back")
bool7 = not bool7
if bool7 then
rs.setBundledOutput("back",current+colors.lightBlue)
else
rs.setBundledOutput("back",current-colors.lightBlue)
end
end
--You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
--The buttons
newButton(1, 2,11,2,8,"Essence",xp)
newButton(2, 14,23,2,8,"Blaze",blaze)
newButton(3, 26,35,2,8,"Wither",wither)
newButton(4, 38,47,2,8,"Ghast",ghast)
newButton(5, 2,11,12,18,"Ender",ender)
newButton(6, 14,23,12,18,"Passive",passive)
newButton(7, 26,35,12,18,"Wisps",wisp)
------------------------------------------------
m.clear()
refreshButtons()
--main loop
while true do
e,side,x,y = os.pullEvent("monitor_touch")
checkxy(x,y)
refreshButtons()
end