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

rs.setBundledOutput() attempt to call number

Started by JacenCaedus, 17 July 2013 - 06:08 PM
JacenCaedus #1
Posted 17 July 2013 - 08:08 PM
Hi, I'm a bit new to computercraft and lua in general, but have gotten by on what I know up until now
basically I am trying to create a menu to control my MFR planters and harvesters, I am basing my code off Direwolf20's button API. I am trying to make it so that when I go into the menu, each button will display the state of the planter it controls, based on an external file. When I try to use rs.setBundledOutput to toggle the planter on or off, I get an attempt to call number error, and I am not quite sure what that means

os.loadAPI("button")
m = peripheral.wrap("left")
m.clear()
file = fs.open("jacencaedus/buttonstates","r")--this is where the number that controls the rsBundledOutput is stored
bStates = file.readAll()
bStatesN = tonumber(bStates)--for later use
file.close()

local switches = {}
local loopControl = true

function fillTable()--position the buttons
  local w,h = m.getSize()
  button.clearTable()
  button.heading("Planter Control", 1)
  button.setTable("Sugar Cane", sugar,8,18,4,6)
  button.setTable("Main Menu",back,(w/2)-5,(w/2)+5,h-4,h-2)
  button.screen()
end

function switch(name)
  switches[name] = not switches[name]
  term.setCursorPos(1,2)
  term.write("Switched")
end

function back()
  button.flash("Main Menu")
  loopControl = false
  bStates = tostring(rs.getBundledOutput("back"))
  file = fs.open("jacencaedus/buttonstates","w")
  file.write(bStates)--write the rs.bundledOutput to the file
  file.close()
  shell.run("startup")
end

function sugar()--called when the button is pressed
  if not switches["Sugar Cane"] then --if the "Sugar Cane" button is off
    rs.setBundledOutput("back", rs.getBundledInput("back")+colors.white())--enable the white bundle--the problem is right around here
  else
    rs.setBundledOutput("back", rs.getBundledInput("back")-colors.white())--disable the white bundle
  end
  switch("Sugar Cane")--toggle the button
end

function initSwitches()
  switches["Main Menu"] = false
  switches["Sugar Cane"] = false
end

fillTable()
sleep(0.1)
initSwitches()
rs.setBundledOutput("back",bStatesN)--set the bundled output to what the file had stored
if bStatesN > 1 then--test if the button should be on
  switch("Sugar Cane")
end

while loopControl do
  local timeout = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "monitor_touch" then
    button.checkxy(event[3], event[4])
  elseif event[1] == "timer" and event[2] == timeout then
  end 
end

I will be able to easily expand this later by adding more if statements into the if statement on line 55 to test for the subsequent colors
and here is the button API I am using in case you need it


local mon = peripheral.wrap("left")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.black)

function clearTable()
   button = {}
   mon.clear()
end
			  
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 funcName()
   print("You clicked buttonText")
end
	  
function fillTable()
   setTable("ButtonText", funcName, 5, 25, 4, 8)
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"] - string.len(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"] - string.len(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.lime else currColor = colors.red 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
		    --data["active"] = not data["active"]
		    --print(name)
		 end
	  end
   end
   return false
end
	
function heading(text, line)
   w, h = mon.getSize()
   mon.setCursorPos((w-string.len(text))/2+1, line)
   mon.write(text)
end
	
function label(w, h, text)
   mon.setCursorPos(w, h)
   mon.write(text)
end

Any help you could offer would be much appreciated
Lyqyd #2
Posted 17 July 2013 - 08:59 PM
Split into new topic.

Use `colors.white` instead of `colors.white()`.
JacenCaedus #3
Posted 17 July 2013 - 10:21 PM
well that was simple, but now it's not saving the state of the button to the file
Lyqyd #4
Posted 18 July 2013 - 12:53 AM
Put fillTable below the declarations for back and sugar.
JacenCaedus #5
Posted 18 July 2013 - 12:13 PM
yup that did it, didn't realize the position of a function could affect the result that much
albrat #6
Posted 18 July 2013 - 03:39 PM
the way Lua parses the file is top to bottom. It tries to load everything in order. If you have a function that is called inside another function, you must define the Called function before the Calling function, otherwise it errors with attempt to call ? : nil value (or something like that, it tries to read the function as a varible)

it is the exact same with loading API's - they are just a list of functions, so should be loaded first. (look at any application source code for #c and they call all the #include statements first then start defining varibles, functions, main, then at the end they call the main() … you don't need to understand what is happenening but it shows a good structure. )
JacenCaedus #7
Posted 20 July 2013 - 04:03 AM
well, was just trying to modify the code after the fixes, because for some reason after a while the program would turn off one of the rs signals whenever I called the program. and for some reason, now it is saying that rs.setBundledOutput, expected a string,number which is what I gave it, here's the updated code


os.loadAPI("button")
m = peripheral.wrap("left")
m.clear()
file = fs.open("jacencaedus/buttonstates","r")--this is where the number that controls the rsBundledOutput is stored
bStates = file.readAll()
bStatesN = tonumber(bStates)--for later use
file.close()

local switches = {}
local loopControl = true

function back()
  button.flash("Main Menu")
  loopControl = false
  file = fs.open("jacencaedus/buttonstates","w")
  file.write(tostring(bStatesN))--write the rs.bundledOutput to the file
  file.close()
  shell.run("startup")
end

function sugar()--called when the button is pressed
  if not switches["Sugar Cane"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.white))--enable the white bundle
    bStatesN = bStatesN - colors.white
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.white))--disable the white bundle
    bStatesN = bStatesN + colors.white
  end
  button.toggleButton("Sugar Cane")--toggle the button
end

function wood()--called when the button is pressed
  if not switches["Wood"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.orange))--enable the orange bundle
    bStatesN = bStatesN - colors.orange
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.orange))--disable the orange bundle
    bStatesN = bStatesN + colors.orange
  end
  button.toggleButton("Wood")--toggle the button
end

function barl()--called when the button is pressed
  if not switches["Barl,BB,Chilli"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.magenta))--enable the magenta bundle
    bStatesN = bStatesN - colors.magenta
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.magenta))--disable the magenta bundle
    bStatesN = bStatesN + colors.magenta
  end
  button.toggleButton("Barl,BB,Chilli")--toggle the button
end

function cucumber()--called when the button is pressed
  if not switches["Cuc,Grape"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lightBlue))--enable the lightBlue bundle
    bStatesN = bStatesN - colors.lightBlue
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lightBlue))--disable the lightBlue bundle
    bStatesN = bStatesN + colors.lightBlue
  end
  button.toggleButton("Cuc,Grape")--toggle the button
end

function melon()--called when the button is pressed
  if not switches["Melon,RSP,SB"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.yellow))--enable the yellow bundle
    bStatesN = bStatesN - colors.yellow
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.yellow))--disable the yellow bundle
    bStatesN = bStatesN + colors.yellow
  end
  button.toggleButton("Melon,RSP,SB")--toggle the button
end

function wheat()--called when the button is pressed
  if not switches["Wheat,Corn,Tom"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lime))--enable the lime bundle
    bStatesN = bStatesN - colors.lime
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lime))--disable the lime bundle
    bStatesN = bStatesN + colors.lime
  end
  button.toggleButton("Wheat,Corn,Tom")--toggle the button
end

function diamond()--called when the button is pressed
  if not switches["Cop,Dmnd,Gold"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.pink))--enable the pink bundle
    bStatesN = bStatesN - colors.pink
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.pink))--disable the pink bundle
    bStatesN = bStatesN + colors.pink
  end
  button.toggleButton("Cop,Dmnd,Gold")--toggle the button
end

function iron()--called when the button is pressed
  if not switches["Iron,Lap,Neth"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.gray))--enable the gray bundle
    bStatesN = bStatesN - colors.gray
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.gray))--disable the gray bundle
    bStatesN = bStatesN + colors.gray
  end
  button.toggleButton("Iron,Lap,Neth")--toggle the button
end

function blaze()--called when the button is pressed
  if not switches["Blaze,Dye,Em"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lightGray))--enable the lightGray bundle
    bStatesN = bStatesN - colors.lightGray
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lightGray))--disable the lightGray bundle
    bStatesN = bStatesN + colors.lightGray
  end
  button.toggleButton("Blaze,Dye,Em")--toggle the button
end

function ender()--called when the button is pressed
  if not switches["End,Expl,Glow"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.cyan))--enable the cyan bundle
    bStatesN = bStatesN - colors.cyan
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.cyan))--disable the cyan bundle
    bStatesN = bStatesN + colors.cyan
  end
  button.toggleButton("End,Expl,Glow")--toggle the button
end

function obsidian()--called when the button is pressed
  if not switches["Obs,RS,Tin"] then --if the  button is off
    rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.purple))--enable the purple bundle
    bStatesN = bStatesN - colors.purple
  else
    rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.purple))--disable the purple bundle
    bStatesN = bStatesN + colors.purple
  end
  button.toggleButton("Obs,RS,Tin")--toggle the button
end

function fillTable()--position the buttons
  local w,h = m.getSize()
  button.clearTable()
  button.heading("Planter Control", 1)
  button.setTable("Sugar Cane", sugar,1,17,4,6)
  button.setTable("Wood", wood, 19,35,4,6)
  button.setTable("Barl,BB,Chilli",barl,37,50,4,6)
  button.setTable("Cuc,Grape",cucumber,1,17,8,10)
  button.setTable("Melon,RSP,SB",melon,19,35,8,10)
  button.setTable("Wheat,Corn,Tom",wheat,37,50,8,10)
  button.setTable("Cop,Dmnd,Gold",diamond,1,17,12,14)
  button.setTable("Iron,Lap,Neth",iron,19,35,12,14)
  button.setTable("Blaze,Dye,Em",blaze,37,50,12,14)
  button.setTable("End,Expl,Glow",ender,1,17,16,18)
  button.setTable("Obs,RS,Tin", obsidian,37,50,16,18)
  button.setTable("Main Menu",back,(w/2)-5,(w/2)+5,h-3,h-1)
  button.screen()
end

function initSwitches()
  switches["Main Menu"] = false
  switches["Sugar Cane"] = false
  switches["Wood"] = false
  switches["Barl,BB, Chilli"] = false
  switches["Cuc,Grape"] = false
  switches["Melon, RSP, SB"] = false
  switches["Wheat, Corn, Tom"] = false
  switches["Cop, Dmnd, Gold"] = false
  switches["Iron, Lap, Neth"] = false
  switches["Blaze, Dye, Em"] = false
  switches["End, Expl, Glow"] = false
  switches["Obs, RS, Tin"] = false
end

fillTable()
sleep(0.1)
initSwitches()
rs.setBundledOutput("back",bStatesN)--set the bundled output to what the file had stored -- the issue is here
if not colors.test(bStatesN,colors.white) then--test if the button should be on
  button.toggleButton("Sugar Cane")
end

if not colors.test(bStatesN,colors.orange) then--test if the button should be on
  button.toggleButton("Wood")
end

if not colors.test(bStatesN,colors.magenta) then--test if the button should be on
  button.toggleButton("Barl,BB,Chilli")
end

if not colors.test(bStatesN,colors.lightBlue) then--test if the button should be on
  button.toggleButton("Cuc,Grape")
end

if not colors.test(bStatesN,colors.yellow) then--test if the button should be on
  button.toggleButton("Melon,RSP,SB")
end

if not colors.test(bStatesN,colors.lime) then--test if the button should be on
  button.toggleButton("Wheat,Corn,Tom")
end

if not colors.test(bStatesN,colors.pink) then--test if the button should be on
  button.toggleButton("Cop,Dmnd,Gold")
end

if not colors.test(bStatesN,colors.gray) then--test if the button should be on
  button.toggleButton("Iron,Lap,Neth")
end

if not colors.test(bStatesN,colors.lightGray) then--test if the button should be on
  button.toggleButton("Blaze,Dye,Em")
end

if not colors.test(bStatesN,colors.cyan) then--test if the button should be on
  button.toggleButton("End,Expl,Glow")
end

if not colors.test(bStatesN,colors.purple) then--test if the button should be on
  button.toggleButton("Obs,RS,Tin")
end

while loopControl do
  local timeout = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "monitor_touch" then
    button.checkxy(event[3], event[4])
  elseif event[1] == "timer" and event[2] == timeout then
  end
end
albrat #8
Posted 20 July 2013 - 07:13 AM
The error code in full would be very helpfull :)/> I took the program, put into a computer quickly and tested it…

:179: Expected string, number – the error.

rs.setBundledOutput("back",bStatesN)

I put a little bit of code in to test what bStatesN was giving as a value and for some reason it started to work…
i don't think I changed anything other than that…
Spoiler

os.loadAPI("button")
m = peripheral.wrap("left")
m.clear()
file = fs.open("jacencaedus/buttonstates","r")--this is where the number that controls the rsBundledOutput is stored
bStates = file.readAll()
bStatesN = tonumber(bStates)--for later use
file.close()
local switches = {}
local loopControl = true
function back()
  button.flash("Main Menu")
  loopControl = false
  file = fs.open("jacencaedus/buttonstates","w")
  file.write(tostring(bStatesN))--write the rs.bundledOutput to the file
  file.close()
  shell.run("startup")
end
function sugar()--called when the button is pressed
  if not switches["Sugar Cane"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.white))--enable the white bundle
	bStatesN = bStatesN - colors.white
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.white))--disable the white bundle
	bStatesN = bStatesN + colors.white
  end
  button.toggleButton("Sugar Cane")--toggle the button
end
function wood()--called when the button is pressed
  if not switches["Wood"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.orange))--enable the orange bundle
	bStatesN = bStatesN - colors.orange
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.orange))--disable the orange bundle
	bStatesN = bStatesN + colors.orange
  end
  button.toggleButton("Wood")--toggle the button
end
function barl()--called when the button is pressed
  if not switches["Barl,BB,Chilli"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.magenta))--enable the magenta bundle
	bStatesN = bStatesN - colors.magenta
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.magenta))--disable the magenta bundle
	bStatesN = bStatesN + colors.magenta
  end
  button.toggleButton("Barl,BB,Chilli")--toggle the button
end
function cucumber()--called when the button is pressed
  if not switches["Cuc,Grape"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lightBlue))--enable the lightBlue bundle
	bStatesN = bStatesN - colors.lightBlue
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lightBlue))--disable the lightBlue bundle
	bStatesN = bStatesN + colors.lightBlue
  end
  button.toggleButton("Cuc,Grape")--toggle the button
end
function melon()--called when the button is pressed
  if not switches["Melon,RSP,SB"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.yellow))--enable the yellow bundle
	bStatesN = bStatesN - colors.yellow
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.yellow))--disable the yellow bundle
	bStatesN = bStatesN + colors.yellow
  end
  button.toggleButton("Melon,RSP,SB")--toggle the button
end
function wheat()--called when the button is pressed
  if not switches["Wheat,Corn,Tom"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lime))--enable the lime bundle
	bStatesN = bStatesN - colors.lime
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lime))--disable the lime bundle
	bStatesN = bStatesN + colors.lime
  end
  button.toggleButton("Wheat,Corn,Tom")--toggle the button
end
function diamond()--called when the button is pressed
  if not switches["Cop,Dmnd,Gold"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.pink))--enable the pink bundle
	bStatesN = bStatesN - colors.pink
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.pink))--disable the pink bundle
	bStatesN = bStatesN + colors.pink
  end
  button.toggleButton("Cop,Dmnd,Gold")--toggle the button
end
function iron()--called when the button is pressed
  if not switches["Iron,Lap,Neth"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.gray))--enable the gray bundle
	bStatesN = bStatesN - colors.gray
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.gray))--disable the gray bundle
	bStatesN = bStatesN + colors.gray
  end
  button.toggleButton("Iron,Lap,Neth")--toggle the button
end
function blaze()--called when the button is pressed
  if not switches["Blaze,Dye,Em"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.lightGray))--enable the lightGray bundle
	bStatesN = bStatesN - colors.lightGray
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.lightGray))--disable the lightGray bundle
	bStatesN = bStatesN + colors.lightGray
  end
  button.toggleButton("Blaze,Dye,Em")--toggle the button
end
function ender()--called when the button is pressed
  if not switches["End,Expl,Glow"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.cyan))--enable the cyan bundle
	bStatesN = bStatesN - colors.cyan
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.cyan))--disable the cyan bundle
	bStatesN = bStatesN + colors.cyan
  end
  button.toggleButton("End,Expl,Glow")--toggle the button
end
function obsidian()--called when the button is pressed
  if not switches["Obs,RS,Tin"] then --if the  button is off
	rs.setBundledOutput("back", colors.subtract(rs.getBundledInput("back"),colors.purple))--enable the purple bundle
	bStatesN = bStatesN - colors.purple
  else
	rs.setBundledOutput("back", colors.combine(rs.getBundledInput("back"),colors.purple))--disable the purple bundle
	bStatesN = bStatesN + colors.purple
  end
  button.toggleButton("Obs,RS,Tin")--toggle the button
end
function fillTable()--position the buttons
  local w,h = m.getSize()
  button.clearTable()
  button.heading("Planter Control", 1)
  button.setTable("Sugar Cane", sugar,1,17,4,6)
  button.setTable("Wood", wood, 19,35,4,6)
  button.setTable("Barl,BB,Chilli",barl,37,50,4,6)
  button.setTable("Cuc,Grape",cucumber,1,17,8,10)
  button.setTable("Melon,RSP,SB",melon,19,35,8,10)
  button.setTable("Wheat,Corn,Tom",wheat,37,50,8,10)
  button.setTable("Cop,Dmnd,Gold",diamond,1,17,12,14)
  button.setTable("Iron,Lap,Neth",iron,19,35,12,14)
  button.setTable("Blaze,Dye,Em",blaze,37,50,12,14)
  button.setTable("End,Expl,Glow",ender,1,17,16,18)
  button.setTable("Obs,RS,Tin", obsidian,37,50,16,18)
  button.setTable("Main Menu",back,(w/2)-5,(w/2)+5,h-3,h-1)
  button.screen()
end
function initSwitches()
  switches["Main Menu"] = false
  switches["Sugar Cane"] = false
  switches["Wood"] = false
  switches["Barl,BB, Chilli"] = false
  switches["Cuc,Grape"] = false
  switches["Melon, RSP, SB"] = false
  switches["Wheat, Corn, Tom"] = false
  switches["Cop, Dmnd, Gold"] = false
  switches["Iron, Lap, Neth"] = false
  switches["Blaze, Dye, Em"] = false
  switches["End, Expl, Glow"] = false
  switches["Obs, RS, Tin"] = false
end
fillTable()
sleep(0.1)
initSwitches()
--[[ Test Code
print(bStatesN)
--]]
rs.setBundledOutput("back",bStatesN)--set the bundled output to what the file had stored -- the issue is here
if not colors.test(bStatesN,colors.white) then--test if the button should be on
  button.toggleButton("Sugar Cane")
end
if not colors.test(bStatesN,colors.orange) then--test if the button should be on
  button.toggleButton("Wood")
end
if not colors.test(bStatesN,colors.magenta) then--test if the button should be on
  button.toggleButton("Barl,BB,Chilli")
end
if not colors.test(bStatesN,colors.lightBlue) then--test if the button should be on
  button.toggleButton("Cuc,Grape")
end
if not colors.test(bStatesN,colors.yellow) then--test if the button should be on
  button.toggleButton("Melon,RSP,SB")
end
if not colors.test(bStatesN,colors.lime) then--test if the button should be on
  button.toggleButton("Wheat,Corn,Tom")
end
if not colors.test(bStatesN,colors.pink) then--test if the button should be on
  button.toggleButton("Cop,Dmnd,Gold")
end
if not colors.test(bStatesN,colors.gray) then--test if the button should be on
  button.toggleButton("Iron,Lap,Neth")
end
if not colors.test(bStatesN,colors.lightGray) then--test if the button should be on
  button.toggleButton("Blaze,Dye,Em")
end
if not colors.test(bStatesN,colors.cyan) then--test if the button should be on
  button.toggleButton("End,Expl,Glow")
end
if not colors.test(bStatesN,colors.purple) then--test if the button should be on
  button.toggleButton("Obs,RS,Tin")
end
while loopControl do
  local timeout = os.startTimer(1)
  local event = {os.pullEvent()}
  if event[1] == "monitor_touch" then
	button.checkxy(event[3], event[4])
  elseif event[1] == "timer" and event[2] == timeout then
  end
end

I have a suspicion that a sleep(0.5) in there might avoid the problem, (just before line 179).
JacenCaedus #9
Posted 20 July 2013 - 04:44 PM
thanks, tested it, and yeah the sleep(0.5) before 179 did the trick