gknova61

Utility API

Jan 16th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. -- This is written by me. If you see this, feel free to suggest new ideas for more functions to fit in with this API on the forums!
  2.  
  3. --Just waits for events and prints the event name, and its parameters out all nicely
  4. function eventSniff()
  5.   while true do
  6.     local ev = {os.pullEvent()}
  7.     for k,v in pairs(ev) do
  8.       if k == 1 then
  9.         print("Event Name : "..v)
  10.       else
  11.         print("param "..(k-1).." : "..v)
  12.       end
  13.     end
  14.   end
  15. end
  16.  
  17. --Checks every side for a peripheral and if there is one, it prints the type of peripheral as well as the methods for it
  18. function checkAllPeripheral()
  19.   for k,v in pairs(rs.getSides()) do
  20.     if peripheral.isPresent(v) then
  21.       print("Side: "..v)
  22.       print("Type: "..peripheral.getType(v))
  23.       print("Methods: ")
  24.       for k2,v2 in pairs(peripheral.getMethods(v)) do
  25.         print(v2)
  26.       end
  27.     end
  28.   end
  29. end
  30.  
  31. --Checks every side for a specified peripheral (name variable) and if it is present, it'll return the side it is present on. Varname is optional and all you'd do is put a string there for example "p" and if it finds the peripheral you're looking for, it'll automatically wrap it to that string (p = peripheral.wrap("left"))
  32. function peripheralGet(name,varname)
  33.   for k,v in pairs(rs.getSides()) do
  34.     if peripheral.getType(v) == name then
  35.       if varname ~= nil then
  36.         local tb1 = {}
  37.         tb1[varname] = peripheral.wrap(v)
  38.         return true
  39.       else
  40.         return v
  41.       end
  42.     end
  43.   end
  44.   return false
  45. end
Advertisement
Add Comment
Please, Sign In to add comment