Advertisement
tripl3dogdare

[ComputerCraft] [MiscPeripherals] sHelm API by tripl3dogdare

Jan 1st, 2014
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. --[[
  2.  
  3. sHelm API by tripl3dogdare
  4. http://www.youtube.com/user/tripl3dogdare
  5.  
  6. What it does: This API works with and improves the MiscPeripherals Smart Helmet peripheral.
  7.  
  8. Why: The Smart Helmet is... a hassle. And not very powerful. (At first glance...) This API attempts to improve the
  9. user experience of programming for the SH, while also adding some useful and powerful functions. (like the ability
  10. to print a table straight to the SH without some weird workaround crap)
  11.  
  12. Have fun creating awesome stuff with the Smart Helmet HUD!
  13.  
  14. ]]--
  15.  
  16. function attachSender() -- runs through all sides, if it finds a SmallnetSender it attaches it and stops.
  17.     for i = 1,6 do -- defining side names
  18.         if i == 1 then
  19.             side = "left"
  20.         elseif i == 2 then
  21.             side = "back"
  22.         elseif i == 3 then
  23.             side = "right"
  24.         elseif i == 4 then
  25.             side = "front"
  26.         elseif i == 5 then
  27.             side = "top"
  28.         else
  29.             side = "bottom"
  30.         end
  31.  
  32.     if peripheral.getType(side) == "smNetSender" then -- check if peripheral type is correct, can also come up nil with no errors
  33.         helm = peripheral.wrap(side) -- if found, wraps to name "helm"
  34.         break
  35.     end
  36. end
  37. end
  38.  
  39. function send(message) -- simpler sending!
  40.     helm.send("smartHelmet",message) -- simplest function of the bunch, just slaps on the message type and sends
  41. end
  42.  
  43. function sendTable(table, delay) -- send a table with ease!
  44.     delay = delay or nil -- just makes delay optional, ignore this
  45.     for i = 1,#table do -- go through the whole table and nothing more
  46.         send(table[i]) -- send just the message from that index
  47.         if delay ~= nil then
  48.             sleep(delay) -- sleep for the set delay if there is one
  49.         end
  50.     end
  51. end
  52.  
  53. function clear() -- clean your Smart Helmet screen in a jiffy!
  54.     for i = 1,5 do -- rotate five times, once for each line on the Smart Helmet display
  55.         send("") -- send an empty message to bump off a single line
  56.     end
  57. end
  58.  
  59. function sendOnTrigger(side, message, delay) -- wait for a redstone input, and send a message then!
  60.     delay = delay or nil -- again, options.
  61.     while true do
  62.         if rs.getInput(side) then -- check for input on specified side
  63.             if delay ~= nil then -- the delay is put in front this time, since you're only sending one thing.
  64.                 sleep(delay)
  65.             end
  66.             send(message) -- send away!
  67.             break -- just so it doesn't keep waiting once it has an input
  68.         else
  69.             sleep(.01) -- just so it doesn't stop waiting before it actually gets an input
  70.         end
  71.     end
  72. end
  73.  
  74. function sendTableOnTrigger(side, table, delay, tableDelay) -- fusion of awesomeness! Send tables on a redstone input!
  75.     delay = delay or nil -- once again, options, options, options.
  76.     tableDelay = tableDelay or nil -- this too
  77.     while true do
  78.         if rs.getInput(side) then -- getting repetitive now =P
  79.             if delay ~= nil then
  80.                 sleep(delay)
  81.             end
  82.             sendTable(table, tableDelay)
  83.             break
  84.         else
  85.             sleep(.01) -- this kind of function is still pretty impatient, so you kind of need this.
  86.         end
  87.     end
  88. end
  89.  
  90. function clearOnTrigger(side, delay)
  91.     delay = delay or nil
  92.     while true do
  93.         if delay ~= nil then
  94.             sleep(delay)
  95.         end
  96.         if rs.getInput(side) then
  97.             clear()
  98.             break
  99.         else
  100.             sleep(.01)
  101.         end
  102.     end
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement