Posted 27 November 2012 - 04:22 AM
I have been tring to come up with a system to change various colours on a bundled cable, then save the resulting number in a file when does, so that when my computer reboots itself it starts back up with the same bundled output as it was left with, doors, lights etc… the problem i either to do with the way the script save the variable or gets it back. i'm pretty confident that i'm setting the bundled cable right,…. its just everything else. anyway here is the code…
Thank you to anybody who takes the time to look at this for me. it is very much appreciated.
local bunside = "bottom" -- declares the side used for bundled cable
local wht = 1 -- 1 for white,
local sFile, scol = "rsData", "" -- declares the file to use.
function load()
if fs.exists(sFile) then
local hRead = assert(fs.open(sFile, "r"))
scol = hRead.readAll() --reads data from file.
hRead.close()
end
end
function save() -- saves the data to a file
hWrite = fs.open(sFile, "w")
hWrite.write(new)
hWrite.close()
end
function add() -- turning a cable on, or adding a color
print ("turning ON")
local new = scol + wht
rs.setBundledOutput(bunside, new)
print ("turned ON")
save(new) -- save variable new
sleep(1)
os.reboot() --return to menu
end
function sub() -- turning off a cable or removing a color
print ("turning OFF")
local new = scol - wht
rs.setBundledOutput(bunside, new)
print ("turned OFF")
save(new) -- save variable new
sleep(1)
os.reboot() -- return to menu
end
function menu() -- display menu
term.setCursorPos(1,1)
print("Please choose an option")
term.setCursorPos(1,2)
write("Select one")
term.setCursorPos(1,3)
end
function select() -- Menu items to display
print("1. Lights")
print("2. option 2")
--you can add more selections if you want
term.setCursorPos(1,6) -- Resets the cursor back to the end of the selection line. Can be changed to any cursor position.
end
function lights() -- function for lighting control
if redstone.testBundledInput("bottom", colors.white) == true then
print("Lights on, Turn off? Y/N")
local input = read()
if input == "y" then
sub() -- run subtract function to turn cable off
else print("Can't do anything, quitting....")
sleep(1)
os.reboot()
end
else print("Lights Off, Turn on? Y/N")
local input = read()
if input == "y" then
add() -- run addition function to turn cable on
else print("Can't do anything, quitting....")
sleep(1)
os.reboot()
end
end
end
-- functions out of the way.... on to the code
term.clear() -- clear the screen
load() -- loads the value from the file..
rs.setBundledOutput(bunside, scol)
mainMenu() -- show the menu
selection() -- show the options
print(scol) -- threw the in here to check if my variable is properly defined. it returns blank.so i guess not
local input = read()
if input == "1" then
lights() -- run the function for the lights.
elseif input == "2" then
print("nothing to do yet")
else
print("OOPS PLEASE TRY AGAIN")
sleep(1)
os.reboot()
end
Thank you to anybody who takes the time to look at this for me. it is very much appreciated.