Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local curfloor
- local sel
- local function loadOnStartup()
- local h = fs.open('.data', 'r') -- hidden file
- assert(h, "ERROR: Could not open data file in read mode.")
- local t1 = h.readLine()
- local t2 = h.readLine()
- h.close()
- if t1 then
- curfloor = t1
- end
- if t2 then
- sel = t2
- end
- end
- local function persistData()
- local h = fs.open('.data', 'w')
- assert(h, "ERROR: Could not open data file in write mode.")
- h.write(curfloor..'\n')
- h.write(sel)
- h.close()
- end
- local function setCurfloor(s)
- curfloor = s
- persistData()
- end
- local function setSel(s)
- sel = s
- persistData()
- end
- local function down(n)
- for i=1, n do
- rs.setBundledOutput("back", colors.white)
- sleep(.5)
- rs.setBundledOutput("back", 0)
- sleep(.5)
- end
- end
- local function up(u)
- for i=1, u do
- rs.setBundledOutput("back", colors.orange)
- sleep(.5)
- rs.setBundledOutput("back", 0)
- sleep(1)
- end
- end
- local function ground()
- print(sel)
- print(curfloor)
- if curfloor == sel then
- print("already here")
- else
- if curfloor == "second" then
- down(5)
- setCurfloor("ground")
- else
- down(22)
- setCurfloor("ground")
- end
- end
- end
- function second()
- print(sel)
- print(curfloor)
- if curfloor == sel then
- print("already here")
- else
- if curfloor == "ground" then
- up(5)
- setCurfloor("second")
- else
- down(17)
- setCurfloor("second")
- end
- end
- end
- function top()
- print(sel)
- print(curfloor)
- if curfloor == sel then
- print("already here")
- else
- if curfloor == "ground" then
- up(22)
- setCurfloor("mountain")
- else
- up(17)
- setCurfloor("mountain")
- end
- end
- end
- rednet.open("right") -- you want to be using channels if you are going to use 'modem_message' not rednet api
- if fs.exists('.data') then
- loadOnStartup()
- else
- curfloor = 'ground'
- sel = 'ground'
- end
- while true do
- local event, side, sendChannel, replyChannel, msg, distSent = os.pullEvent()
- if event == "modem_message" then
- setSel(msg)
- print(event)
- print(sel)
- if sel == "ground" then
- ground()
- elseif sel == "second" then
- second()
- else
- top()
- end
- else
- print("not correct signal")
- end
- end
- --shell.run("elevator")
Advertisement
Add Comment
Please, Sign In to add comment