Posted 02 July 2013 - 04:18 PM
Okay, so I'm making a little program for controlling a few mob spawners. I'm using Direwolf20's "Button API", to make fancy buttons. I've successfully implemented buttons for 6 spawners, and the functions these buttons trigger. I want to be able to save the state of each spawner to a file, so that whenever the server I'm on restarts, the computer will remember the state of each spawner. I've tried to implement this into /one/ of my button functions, with no success. The computer sets the state of the spawner to false each time I press the button, even though it should toggle it. I think this is because I'm doing something wrong with the fs API.
Code:
Code:
os.unloadAPI("button")
os.loadAPI("ButtonAPI")
m = peripheral.wrap("right")
m.clear()
whiteActive = false
orangeActive = false
magentaActive = false
lightBlueActive = false
yellowActive = false
limeActive = false
rs.setBundledOutput("left", 0)
function fillTable()
ButtonAPI.setTable("Enderman #1", enderman1, 4,20,3,5)
ButtonAPI.setTable("Enderman #2", enderman2,4,20,7,9)
ButtonAPI.setTable("Enderman #3", enderman3,4,20,11,13)
ButtonAPI.setTable("Enderman #4", enderman4,4,20,15,17)
ButtonAPI.setTable("Blaze #1", blaze1, 22,38,3,5)
ButtonAPI.setTable("Blaze #2", blaze2, 22,38,7,9)
ButtonAPI.screen()
end
function getClick()
event, side, x, y = os.pullEvent("monitor_touch")
ButtonAPI.checkxy(x,y)
end
function enderman1()
ButtonAPI.toggleButton("Enderman #1")
E1R = fs.open("F1", "r")
whiteState = E1R.readLine()
E1R.close()
if state == "false" then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 1
rs.setBundledOutput("left", newColourNum)
whiteActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 1
rs.setBundledOutput("left", newColourNum)
whiteActiveSet = false
end
E1W = fs.open("F1", "w")
E1W.write(whiteActiveSet)
E1W.close()
print("Enderman Spawner #1 was toggled to: " ..tostring(whiteActiveSet))
end
function enderman2()
ButtonAPI.toggleButton("Enderman #2")
if orangeActive == false then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 2
rs.setBundledOutput("left", newColourNum)
orangeActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 2
rs.setBundledOutput("left", newColourNum)
orangeActiveSet = false
end
orangeActive = orangeActiveSet
print("Enderman Spawner #2 was toggled to: " ..tostring(orangeActive))
end
function enderman3()
ButtonAPI.toggleButton("Enderman #3")
if magentaActive == false then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 4
rs.setBundledOutput("left", newColourNum)
magentaActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 4
rs.setBundledOutput("left", newColourNum)
magentaActiveSet = false
end
magentaActive = magentaActiveSet
print("Enderman Spawner #3 was toggled to: " ..tostring(magentaActive))
end
function enderman4()
ButtonAPI.toggleButton("Enderman #4")
if lightBlueActive == false then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 8
rs.setBundledOutput("left", newColourNum)
lightBlueActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 8
rs.setBundledOutput("left", newColourNum)
lightBlueActiveSet = false
end
lightBlueActive = lightBlueActiveSet
print("Enderman Spawner #4 was toggled to: " ..tostring(lightBlueActive))
end
function blaze1()
ButtonAPI.toggleButton("Blaze #1")
if yellowActive == false then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 16
rs.setBundledOutput("left", newColourNum)
yellowActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 16
rs.setBundledOutput("left", newColourNum)
yellowActiveSet = false
end
yellowActive = yellowActiveSet
print("Blaze Spawner #1 was toggled to: " ..tostring(whiteActive))
end
function blaze2()
ButtonAPI.toggleButton("Blaze #2")
if limeActive == false then
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum + 32
rs.setBundledOutput("left", newColourNum)
limeActiveSet = true
else
colourNum = rs.getBundledOutput("left")
newColourNum = colourNum - 32
rs.setBundledOutput("left", newColourNum)
limeActiveSet = false
end
limeActive = limeActiveSet
print("Blaze Spawner #2 was toggled to: " ..tostring(whiteActive))
end
fillTable()
ButtonAPI.heading("Spawner Control")
while true do
getClick()
end