Advertisement
Guest User

that one door program that i can't fix

a guest
Jul 24th, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. --[[
  2.   this code is poorly optimised and written.
  3.   the functionality of this code is to controll doors. that's it. nothing special.
  4.   future improvements include: larger buttons, key disk support and password support all of which i can do myself.
  5.   reffer to line 42 for detailed info on my issues...
  6. ]]
  7.  
  8. term.clear()
  9. term.setCursorPos(1,1)
  10.  
  11. local oldBgC = term.getBackgroundColor()
  12. local BgC = colors.red
  13. local sOut = false
  14.  
  15. local w,h = term.getSize()
  16.  
  17. while true do
  18.  
  19. --defining button color
  20. local out = rs.getOutput("bottom")
  21.  if out then
  22.   BgC = colors.green
  23.  else
  24.   BgC = colors.red
  25.  end
  26.  
  27. --button "write"
  28. term.setCursorPos(1,1)
  29. term.clearLine()
  30. term.setCursorPos(2,2)
  31. term.setBackgroundColor(BgC)
  32. term.write(" ")
  33. term.setBackgroundColor(oldBgC)
  34.  
  35. --button "handeler"
  36. local event, mb, x, y = os.pullEvent("mouse_click")
  37.  if x == 2 and y == 2 then
  38.    sOut = not out
  39.  end
  40. rs.setOutput("bottom",sOut)
  41.  
  42. --here's where i'm stuck;
  43. --calling exit() causes the program to halt until it's satisfied or errors.
  44. --parallel imo isn't what i'd need rather coroutines.
  45. --but i can't, for the life of me, get them to cooperate dispite
  46. --the lua 5.1, 5.3 manual refferancing.
  47. --all i need help with is getting an input field at the very bottom to be able to
  48. --pass comands and args to the program while still pulling mouse_click events
  49.  
  50. --exit "handeler"
  51. function exit()
  52.  
  53.  term.setCursorPos(1,h-2)
  54.  term.clearLine()
  55.  term.setCursorPos(1,h-1)
  56.  term.write('type "exit()" to exit')
  57.  term.setCursorPos(1,h)
  58.  
  59.   if read() == "exit()" then
  60.    ex = true
  61.   end
  62. end
  63.  
  64. if ex == true then break end
  65.  
  66. --debug, ignore this
  67. --[[
  68. local w,h = term.getSize()
  69. term.setCursorPos(1,h)
  70. term.clearLine()
  71. print("cordinates> "..x..","..y)
  72.  
  73. term.setCursorPos(1,7)
  74. term.clearLine()
  75. --]]
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement