Advertisement
TechManDylan

InspectX

Jun 27th, 2024
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. -- Function to generate a unique filename
  2. function generateFilename()
  3.     local i = 1
  4.     local filename = "inspect" .. i .. ".txt"
  5.     while fs.exists(filename) do
  6.         i = i + 1
  7.         filename = "inspect" .. i .. ".txt"
  8.     end
  9.     return filename
  10. end
  11.  
  12. -- Function to inspect the block in front of the turtle
  13. function inspectBlock()
  14.     local success, data = turtle.inspect()
  15.     if success then
  16.         return data
  17.     else
  18.         return nil
  19.     end
  20. end
  21.  
  22. -- Main function
  23. function main()
  24.     local filename = generateFilename()
  25.     local file = fs.open(filename, "w")
  26.     local blockData = inspectBlock()
  27.    
  28.     if blockData then
  29.         file.writeLine("Block Information:")
  30.         for k, v in pairs(blockData) do
  31.             if type(v) == "table" then
  32.                 file.writeLine(k .. ":")
  33.                 for subKey, subValue in pairs(v) do
  34.                     file.writeLine("  " .. subKey .. ": " .. tostring(subValue))
  35.                 end
  36.             else
  37.                 file.writeLine(k .. ": " .. tostring(v))
  38.             end
  39.         end
  40.     else
  41.         file.writeLine("No block detected.")
  42.     end
  43.  
  44.     file.close()
  45.     print("Inspection data written to " .. filename)
  46. end
  47.  
  48. -- Execute the main function
  49. main()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement