Ahhh, I understand now… you want to click the button the first time and turn on the signal, then press again and turn off the signal… that would require some programming changes.
I also found your problem… you are getting the error "button : 65 : attempt to index ?(a nil value)" this is because you wrote the boolean checker for Cow Farm button. You forgot to drop the button menu into the Farm menu and load the Cow Farm menu up, hence the program button crashed out… (the data was not loaded) You need to feed the program with the actions in the correct sequence otherwise the button API gets confused.
I loaded this up on a advanced computer, upon removing your file checks function from the execution list it works perfectly. * I played around a little and wrote the program a little different. – Now the power to the white wire turns on and off as you click the button.
there is a problem with the Button API… it does not save sub table data. This means that every time you click for a new menu it wipes the previous values from the table. so even if your CowBool script changed the value, the button on every reload would default to off (dark) no matter what the output is set too. but clicking the button will change the output.
I have the button turning on and off… After a restart it loads its previous state and does not error out. But as I mentioned the button API by default can not reload states. It would require re-writing to be capable of handling your loaded states.
Here are my code re-writes.
Spoiler
--[[ VARIABLES ]]--
local mon = peripheral.wrap("top")
local CowBool = false
--[[ FUNCTIONS ]]--
os.loadAPI("button") -- Bunch of functions. Gave errors because it was not loaded first
function MainButtons()
button.setTable("Farm Menu", FarmMenu, 10, 20, 3, 5)
button.setTable("Test2", mainb, 22, 32, 3, 5)
button.setTable("Test3", mainc, 10, 20, 8, 10)
button.setTable("Test4", maind, 22, 32, 8, 10)
button.screen()
end
function getClick()
event, side, x, y = os.pullEvent("monitor_touch")
button.checkxy(x,y)
end
function FarmButtons()
button.setTable("Cow Farm", CowFarm, 10, 20, 3, 5)
button.setTable("Blaze Farm", BlazeFarm, 22, 32, 3, 5)
button.setTable("Back", back, 10, 17, 15, 17)
button.screen()
end
function FarmMenu() --Clears the past(main) menu and runs/displays the "Farms" menu
button.flash("Farm Menu")
sleep(.1)
button.clearTable()
FarmButtons()
button.heading("Farms")
end
function mainb()
sleep(1)
--Do Stuff
end
function mainc()
sleep(1)
--Do Stuff
end
function maind()
sleep(1)
--Do stuff
end
function back()
button.flash("Back")
button.clearTable()
MainButtons()
button.heading("N1ght Network")
end
function CowFarm()
CowBool = not CowBool
local filew = fs.open("buttonstates", "w")
filew.writeLine(tostring(CowBool))
filew.close()
button.toggleButton("Cow Farm")
if CowBool then
rs.setBundledOutput("bottom", colors.white)
else
rs.setBundledOutput("bottom", 0)
end
end
function CowFarmL() -- loading file test
local filew = fs.open("buttonstates", "w")
filew.writeLine(tostring(CowBool))
filew.close()
button.toggleButton("Cow Farm")
if CowBool then
rs.setBundledOutput("bottom", colors.white)
else
rs.setBundledOutput("bottom", 0)
end
end
function BlazeFarm()
--Toggle the BlazeFarm
end
function CheckCowBool()
--Checks the file "buttonstates" for the boolean of the CowFarm, and tries to set CowBool to the current, correct state, defined in the file "buttonstates".
if fs.exists("buttonstates") then
local filer = fs.open("buttonstates", "r")
local CowBoole = filer.readLine() == "true"
filer.close()
CowBool = CowBoole
end
sleep(1)
if CowBool then
rs.setBundledOutput("bottom", colors.white)
mon.clear()
MainButtons()
button.heading("N1ght Network")
FarmMenu()
sleep(1)
CowFarmL()
button.screen()
sleep(1)
back()
else
rs.setBundledOutput("bottom", 0)
end
end
--[[ MAIN ]]--
CheckCowBool() -- Our new check function
mon.clear()
MainButtons()
button.heading("N1ght Network")
while true do
getClick()
end
The button API has not been altered, That would take a lot of work to make it work how you are hoping to make it work… (if I understand your intended use of the button API).
Hope this helps..