Guest User

Untitled

a guest
Mar 19th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. local curfloor
  2. local sel
  3.  
  4. local function loadOnStartup()
  5.   local h = fs.open('.data', 'w') -- hidden file
  6.   local t1 = h.readLine()
  7.   local t2 = h.readLine()
  8.   h.close()
  9.  
  10.   if t1 then
  11.     curfloor = t1
  12.   end
  13.  
  14.   if t2 then
  15.     sel = t2
  16.   end
  17. end
  18.  
  19. local function persistData()
  20.   local h = fs.open('.data', 'w')
  21.   h.write(curfloor)
  22.   h.write(sel)
  23.   h.close()
  24. end
  25.  
  26. local function setCurfloor(s)
  27.   curfloor = s
  28.   persistData()
  29. end
  30.  
  31. local function setSel(s)
  32.   sel = s
  33.   persistData()
  34. end
  35.  
  36. local function down(n)
  37.   for i=1, n do
  38.     rs.setBundledOutput("back", colors.white)
  39.     sleep(.5)
  40.     rs.setBundledOutput("back", 0)
  41.     sleep(.5)
  42.   end
  43. end
  44.  
  45. local function up(u)
  46.   for i=1, u do
  47.     rs.setBundledOutput("back", colors.orange)
  48.     sleep(.5)
  49.     rs.setBundledOutput("back", 0)
  50.     sleep(1)
  51.   end
  52. end
  53.  
  54. local function ground()
  55.   print(sel)
  56.   print(curfloor)
  57.  
  58.   if curfloor == sel then
  59.     print("already here")
  60.   else
  61.     if curfloor == "second" then
  62.       down(5)
  63.       setCurfloor("ground")
  64.     else
  65.       down(22)
  66.       setCurfloor("ground")
  67.     end
  68.   end
  69. end
  70.  
  71. function second()
  72.   print(sel)
  73.   print(curfloor)
  74.  
  75.   if curfloor == sel then
  76.     print("already here")
  77.   else
  78.     if curfloor == "ground" then
  79.       up(5)
  80.       setCurfloor("second")
  81.     else
  82.       down(17)
  83.       setCurfloor("second")
  84.     end
  85.   end
  86. end
  87.  
  88. function top()
  89.   print(sel)
  90.   print(curfloor)
  91.  
  92.   if curfloor == sel then
  93.     print("already here")
  94.   else
  95.     if curfloor == "ground" then
  96.       up(22)
  97.       setCurfloor("mountain")
  98.     else
  99.       up(17)
  100.       setCurfloor("mountain")
  101.     end
  102.   end
  103. end
  104.  
  105. rednet.open("right") -- you want to be using channels if you are going to use 'modem_message' not rednet api
  106.  
  107. while true do
  108.   local event, side, sendChannel, replyChannel, msg, distSent = os.pullEvent()
  109.  
  110.   if event == "modem_message" then
  111.     setSel(msg)
  112.     print(event)
  113.     print(sel)
  114.     if sel == "ground" then
  115.       ground()
  116.     elseif sel == "second" then
  117.       second()
  118.     else
  119.       top()
  120.     end
  121.   else
  122.     print("not correct signal")
  123.   end
  124. end
  125.  
  126. --shell.run("elevator")
Advertisement
Add Comment
Please, Sign In to add comment