Guest User

REDSToneKeyReceive

a guest
Mar 17th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. -- Basic RSRPrint - by Mikk809h
  2. -- Redstone Signal Receive Print --
  3. -- mode
  4. local mode = 1
  5. -- 1 = redstone signal. 2 = rednet signal. 3 = key signal.
  6.  
  7. -- Variables --
  8. local AcceptMsg = false
  9. local AcceptkeyMsg = false
  10.  
  11.  
  12.     -- if mode is 1 then only edit this.
  13. local moreSides = {"top", "bottom", "right", "left", "front", "back"};
  14.     -- input side. delete the sides that you dont want to use.
  15. local message = "No signal"; -- if no signal received.
  16. local message2 = "Signal Received"; -- if signal received.
  17.  
  18.  
  19.     -- if mode is 2 then only edit this.
  20. local modemSide = {"top"}; 
  21.     -- leave, if all sides has a modem. (xD)
  22.     -- Turn Signal On When Message Is Received
  23. local messageToReceive = "Hello";
  24.     -- edit the "" to the message you want. like:
  25.     -- if you want it to turn the signal to true, when receiving the message "Hello" then
  26.     -- change(messageToReceive) = "Hello"
  27. local message3 = "No signal received";
  28. local message4 = "Signal received";
  29.  
  30.  
  31.     -- if mode is 3 then only edit this.
  32. local chars = {keys.enter, keys.tab, keys.space, keys.backspace}    -- add keys.key (key is the name of the letter/key.)
  33. -- Signal is received when one of thoose chars is pressed/used.
  34. local message5 = "No signal received";
  35. local message6 = "Signal received";
  36. local messageRec = "Key: " -- a little hotbar at bottom of screen which shows which key is pressed.
  37.  
  38.  
  39.  
  40. --
  41. -- Main
  42. --
  43.  
  44.     -- If you want to return back to shell when done edit this to true.
  45. local stopWhenReceivingSignal = true
  46.  
  47. -- clear screen
  48. term.clear();
  49. term.setCursorPos(1,1) ;
  50.  
  51. -- loop/main
  52. while true do -- loops the checker + the printed text.
  53.     if mode == 1 then
  54.         for k,v in pairs(moreSides) do -- checks all sides in the "moreSides" table.
  55.             if rs.getInput(v) ~= true then -- if the side does not equals to true, then ...
  56.                 term.setCursorPos(1,1) ;
  57.                 term.clearLine() ;
  58.                 term.write(message) ; -- prints the message you want, when it does NOT receive a signal.
  59.             else
  60.                 term.setCursorPos(1,1) ;
  61.                 term.clearLine() ;
  62.                 term.write(message2) ; -- prints the message you want, when it receives a signal.
  63.                 AcceptMsg = true
  64.                 if stopWhenReceivingSignal then -- if you want it to return back to shell after it receives a signal.
  65.                     return false -- breaks the loop and returns to shell.
  66.                 end
  67.             end
  68.         end
  69.     elseif mode == 2 then -- if the mods is for rednet then...
  70.         for k,v in pairs(modemSide) do -- checks all sides in the "modemSide" table.
  71.             if v then
  72.                 rednet.open(v) ; -- opens the sides you have declaired in the modemSide table.
  73.             end
  74.         end
  75.         if AcceptMsg == false then
  76.             term.setCursorPos(1,1) ;
  77.             term.clearLine() ;
  78.             term.write(message3) ;
  79.         end
  80.         local event, id, msg = os.pullEvent("rednet_message") -- make a pull event.
  81.        
  82.         if event == "rednet_message" then
  83.             if msg == messageToReceive then -- if it receives the message.
  84.                 term.setCursorPos(1,1) ;
  85.                 term.clearLine() ;
  86.                 term.write(message4) ; -- prints the message you want, when it does receive a signal.
  87.                 sleep(4)
  88.                 AcceptMsg = true
  89.                 if stopWhenReceivingSignal then -- if you want it to return back to shell after it receives a signal.
  90.                     return false -- breaks the loop and returns to shell.
  91.                 end
  92.             else
  93.                 term.setCursorPos(1,1) ;
  94.                 term.clearLine() ;
  95.                 term.write(message3) ; -- prints the message you want, when it does not receive a signal.
  96.             end
  97.         else
  98.             term.setCursorPos(1,1) ;
  99.             term.write(message3) ;
  100.         end
  101.     elseif mode == 3 then -- if mode is the key event.
  102.         if AcceptkeyMsg == false then
  103.             term.setCursorPos(1,1) ;
  104.             term.clearLine() ;
  105.             term.write(message5) ;
  106.         end
  107.         local event, key = os.pullEvent("key")
  108.         term.setCursorPos(1,19)
  109.         term.clearLine()
  110.         term.write(messageRec)
  111.         term.write(key)
  112.         if event == "key" then
  113.             for k,v in pairs(chars) do
  114.                 if key == chars[k] then
  115.                     term.setCursorPos(1,1) ;
  116.                     term.clearLine() ;
  117.                     term.write(message6) ; -- prints the message you want, when it does receive a signal.
  118.                     AcceptkeyMsg = true
  119.                     if stopWhenReceivingSignal then -- if you want it to return back to shell after it receives a signal.
  120.                         return false -- breaks the loop and returns to shell.
  121.                     else
  122.                         sleep(1)
  123.                         AcceptkeyMsg = false
  124.                     end
  125.                 else
  126.                     term.setCursorPos(1,1) ;
  127.                     term.clearLine() ;
  128.                     term.write(message5) ; -- prints the message you want, when it does not receive a signal.
  129.                 end
  130.             end
  131.         else
  132.             term.setCursorPos(1,1) ;
  133.             term.clearLine() ;
  134.             term.write(message5) ; -- prints the message you want, when it does not receive a signal.
  135.         end
  136.     else
  137.         return false
  138.     end
  139.     sleep(0) ;  -- sleeps 0 seconds so it wouldnt return "too long without yielding..."
  140. end
  141. term.clear()
  142. term.setCursorPos(1,1)
  143. print("Thanks for using RedStoneKey Receive-Print!\n\n")
Advertisement
Add Comment
Please, Sign In to add comment