Posted 03 April 2014 - 06:54 AM
Starting to get back into computercraft again and remembered its all about lua, For some reason I cannot get a variable to change to a different number/text format on a click of a button on the monitor. The 2 swiching buttons actually do change if I manually set it as such, but it refuses to change when you click the button. So in short I am stumped as to why….
Spoiler
side = "top"
backbutton = 0
m = peripheral.wrap(side)
bactive = colors.cyan
binactive=colors.red
tactive=colors.white
tinactive=colors.black
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
rs.setBundledOutput("bottom",0)
function maprules()
backbutton = 1
sleep(0.1)
local m = peripheral.wrap(side)
m.setCursorPos(3,5)
m.setTextScale(1)
m.setTextColor(0x400)
m.write("1. Stay in GameMode 2 at all times")
m.setCursorPos(3,6)
m.write("2. Read all lore books they give information")
m.setCursorPos(3,7)
m.write("3. All puzzles are solveable...some are very difficult")
m.setCursorPos(3,8)
m.write("4. Turn off all types of minimap mods")
m.setCursorPos(5,9)
m.write("(this includes: Zans, Opis, Voxel, X-Ray)")
m.setCursorPos(3,10)
m.write("5. Do not remove Computercraft, it kills the map D:")
m.setCursorPos(11,13)
m.write("For full experience and most fun please use")
m.setCursorPos(16,14)
m.write("DireWolf20 FTB modpack 1.6.4")
sleep(1)
term.setCursorPos(1,1)
end
function reboot()
os.reboot()
end
function testingz()
backbutton = 1
end
newButton(1,2,16,2,2,"Map Rules",maprules)
if (backbutton == 1) then
newButton(2,42,56,25,25,"Back",reboot)
elseif (backbutton == 0) then
newButton(2,42,56,25,25,"Start Map",reboot)
end
newButton(3,12,26,4,4,"Testing",testingz)
m.clear()
refreshButtons()
while true do
e,side,x,y = os.pullEvent("monitor_touch")
checkxy(x,y)
refreshButtons()
end