Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to generate a unique filename
- function generateFilename()
- local i = 1
- local filename = "inspect" .. i .. ".txt"
- while fs.exists(filename) do
- i = i + 1
- filename = "inspect" .. i .. ".txt"
- end
- return filename
- end
- -- Function to inspect the block in front of the turtle
- function inspectBlock()
- local success, data = turtle.inspect()
- if success then
- return data
- else
- return nil
- end
- end
- -- Main function
- function main()
- local filename = generateFilename()
- local file = fs.open(filename, "w")
- local blockData = inspectBlock()
- if blockData then
- file.writeLine("Block Information:")
- for k, v in pairs(blockData) do
- if type(v) == "table" then
- file.writeLine(k .. ":")
- for subKey, subValue in pairs(v) do
- file.writeLine(" " .. subKey .. ": " .. tostring(subValue))
- end
- else
- file.writeLine(k .. ": " .. tostring(v))
- end
- end
- else
- file.writeLine("No block detected.")
- end
- file.close()
- print("Inspection data written to " .. filename)
- end
- -- Execute the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement