April_The_Sergal

Print peripheral

Jul 21st, 2025
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. -- CC:Tweaked Peripheral Method Inspector
  2. -- Wraps the bottom peripheral and writes all methods to m.txt
  3.  
  4. -- Check if there's a peripheral on the bottom
  5. local bottomPeripheral = peripheral.wrap("bottom")
  6.  
  7. if not bottomPeripheral then
  8. print("Error: No peripheral found on the bottom side")
  9. return
  10. end
  11.  
  12. -- Get the peripheral type for informational purposes
  13. local peripheralType = peripheral.getType("bottom")
  14. print("Found peripheral: " .. peripheralType)
  15.  
  16. -- Get all methods from the peripheral
  17. local methods = peripheral.getMethods("bottom")
  18.  
  19. if not methods or #methods == 0 then
  20. print("Error: No methods found for the bottom peripheral")
  21. return
  22. end
  23.  
  24. -- Sort methods alphabetically for better organization
  25. table.sort(methods)
  26.  
  27. -- Open file for writing
  28. local file = fs.open("m.txt", "w")
  29.  
  30. if not file then
  31. print("Error: Could not create m.txt file")
  32. return
  33. end
  34.  
  35. -- Write header information
  36. file.writeLine("Peripheral Methods for: " .. peripheralType)
  37. file.writeLine("Location: bottom")
  38. file.writeLine("Total methods: " .. #methods)
  39. file.writeLine(string.rep("-", 40))
  40. file.writeLine("")
  41.  
  42. -- Write each method to the file
  43. for i, method in ipairs(methods) do
  44. file.writeLine(i .. ". " .. method)
  45. end
  46.  
  47. -- Close the file
  48. file.close()
  49.  
  50. print("Successfully wrote " .. #methods .. " methods to m.txt")
  51. print("Methods from " .. peripheralType .. " peripheral have been saved!")
  52.  
  53. -- Optional: Display first few methods on screen
  54. print("\nFirst few methods:")
  55. for i = 1, math.min(5, #methods) do
  56. print(" " .. methods[i])
  57. end
  58.  
  59. if #methods > 5 then
  60. print(" ... and " .. (#methods - 5) .. " more (see m.txt for full list)")
  61. end
Advertisement
Add Comment
Please, Sign In to add comment