Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bedrockPath='Build/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
- local baseRestAPI = 'http://45.76.117.50:8080/datastore/'
- local program, currentState
- function init()
- program = Bedrock:Initialise()
- program:Run(function()
- program:LoadView('main')
- -- Make sure the button is up to date with current reactor state
- currentState = getReactorState()
- local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
- local newColour = currentState and colors.green or colors.red
- program:GetObject('labelState').Text = newText
- program:GetObject('labelState').TextColour = newColour
- program:GetObject('reactorState').OnClick = function(self, event, side, x, y)
- currentState = not currentState
- local newText = currentState and 'Reactor State: ON' or 'Reactor State: OFF'
- local newColour = currentState and colors.green or colors.red
- program:GetObject('labelState').Text = 'OFF'
- program:GetObject('labelState').TextColour = newColour
- program:StartTimer(function()setReactorState(currentState)end, 0.1)
- end
- end)
- end
- function getReactorState()
- local reactorRequest = http.get(baseRestAPI..'get/namar_reactor/state')
- local requestContent = reactorRequest.readAll()
- local reactorState = requestContent == 'error:nostore' or requestContent == 'true' or false
- reactorRequest.close()
- return reactorState
- end
- function setReactorState(bool)
- http.request(baseRestAPI..'set/namar_reactor/state/'..tostring(bool))
- end
- -- Start Init Function
- init()
Advertisement
Add Comment
Please, Sign In to add comment