Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loaded = false
- dir = ""
- file = ""
- path = ""
- internal = {}
- tArgs = {...}
- local function create()
- local file = fs.open(path,"a")
- file.close()
- end
- function autoUpdate( fileName2,pastebinRaw )
- while true do
- local downloadedFile = http.request("http://pastebin.com/raw.php?i="..pastebinRaw)
- local event, url, body = os.pullEvent()
- if event == "http_success" then
- _tBody = body.readAll()
- break
- elseif event == "http_failed" then
- break
- end
- end
- file = fs.open(fileName2, "r")
- _fBody = file.readAll()
- file.close()
- local selection = 1
- if _fBody ~= _tBody then
- print("Update found!")
- sleep(0.5)
- fs.delete(fileName2)
- file = fs.open(fileName2, "w")
- file.write(_tBody)
- file.close()
- --shell.run
- error()
- end
- end
- autoUpdate("state","xQLT79bH")
- local function load(directory,fileName)
- dir = directory
- file = fileName
- if dir ~= nil then
- path = dir.."/"..file
- fs.makeDir(dir)
- create(path)
- local file = fs.open(path, "r")
- repeat
- line = file.readLine()
- if(line ~= nil) then
- local asWords = line:gsub(":","")
- local parts = {}
- for word in asWords:gmatch("%w+") do table.insert(parts,word) end
- internal[parts[1]] = parts[2]
- end
- until line == nil
- loaded = true
- file.close()
- else
- path = file
- create(path)
- local file = fs.open(path, "r")
- repeat
- line = file.readLine()
- if(line ~= nil) then
- local asWords = line:gsub(":","")
- local parts = {}
- for word in asWords:gmatch("%w+") do table.insert(parts,word) end
- internal[parts[1]] = parts[2]
- end
- until line == nil
- loaded = true
- file.close()
- end
- end
- local function writeVal(key,value)
- if(loaded == false) then
- return false
- else
- local toWrite = value
- if(value == true) then toWrite = "true"
- elseif(value == false) then toWrite = "false" end
- internal[key] = toWrite
- return true
- end
- end
- local function readVal(key)
- if(loaded == false) then
- return nil
- end
- toReturn = internal[key]
- if(toReturn == "true") then return true
- elseif(toReturn == "false") then return false
- else return internal[key] end
- end
- local function save()
- if(loaded == true) then
- local file = fs.open(path,"w")
- for i,v in pairs(internal) do
- file.writeLine(i.." = "..v)
- end
- file.close()
- internal = {}
- loaded = false
- return true
- else
- return false
- end
- end
- local function isEmpty()
- if(loaded == false) then
- return nil
- end
- if(fs.getSize(path) == 0)then
- return true
- else return false end
- end
- local function printUsage()
- print("Usage:")
- print(shell.getRunningProgram().." <time-to-run> <interval> <side> <inputSide> (pulseTime)")
- print("Parameters:")
- print("[] = Required")
- print("() = Optional")
- return true
- end
- local function errorCheck()
- local sides = rs.getSides()
- local tArg1Valid = false
- local tArg2Valid = false
- local tArg3Valid = false
- for i=1,#sides do
- if tArgs[3] == sides[i] then
- tArg2Valid = true
- break
- end
- end
- for i=1,#sides do
- if tArgs[4] == sides[i] then
- tArg3Valid = true
- break
- end
- end
- if tonumber(tArgs[2]) == nil then
- error("Interval must be a number!")
- end
- if tArg2Valid then
- else
- error("Invalid side!")
- end
- if tArg3Valid then
- elseif not tArg3Valid then
- error("Invalid input side!")
- end
- end
- if #tArgs < 4 and not fs.exists("config") then
- printUsage()
- return false
- end
- if tArgs[1] == "usage" then
- printUsage()
- return false
- end
- errorCheck()
- if noArgsGood == nil then
- timeToRun = tonumber(tArgs[1])
- interval = tonumber(tArgs[2])
- side = tArgs[3]
- inputStop = tArgs[4]
- pulseTime = tonumber(tArgs[5])
- load(nil,"config")
- writeVal("interval",tostring(interval))
- writeVal("side",side)
- writeVal("inputStop",inputStop)
- writeVal("pulseTime",tostring(pulseTime))
- writeVal("timeToRun",tostring(timeToRun))
- save()
- elseif noArgsGood then
- load(nil,"config")
- interval = tonumber(readVal("interval"))
- side = readVal("side")
- inputStop = readVal("inputStop")
- pulseTime = tonumber(readVal("pulseTime"))
- timeToRun = tonumber(readVal("timeToRun"))
- save()
- end
- if pulseTime == nil then
- pulseTime = 0.2
- end
- while true do
- intervalTimer = os.startTimer(interval)
- print("Declared variable intervalTimer")
- local event = {os.pullEvent()}
- if event[1] == "redstone" and rs.getInput(inputStop) then
- rs.setOutput(side,true)
- sleep(pulseTime)
- rs.setOutput(side,false)
- elseif event[1] == "redstone" and not rs.getInput(inputStop) then
- if timeToRunTimer == nil then
- timeToRunTimer = print(os.startTimer(timeToRun))
- end
- rs.setOutput(side,true)
- sleep(pulseTime)
- rs.setOutput(side,false)
- elseif event[1] == "timer" then
- if rs.getInput(inputStop) then
- print("Getting front")
- rs.setOutput(side,true)
- sleep(pulseTime)
- rs.setOutput(side,false)
- elseif not rs.getInput(inputStop) then
- print("not getting front")
- if timeToRunTimer == nil then
- timeToRunTimer = print(os.startTimer(timeToRun))
- end
- rs.setOutput(side,true)
- sleep(pulseTime)
- rs.setOutput(side,false)
- end
- if event[2] == intervalTimer then
- print("doing redstone stuff")
- rs.setOutput(side,true)
- sleep(pulseTime)
- rs.setOutput(side,false)
- elseif event[2] == timeToRunTimer then
- print("event[2] == timeToRunTimer")
- local timeToRunTimer = nil
- rs.setOutput(side,false)
- while true do
- local event = {os.pullEvent("redstone")}
- if event[1] == "redstone" and rs.getInput(inputStop) then
- break
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment