Advertisement
Myros27

debug

May 16th, 2025 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. -- Script: diagnose_orders_to_file.lua
  2. -- Purpose: Dumps detailed information about all active work orders and their resources to a file.
  3.  
  4. local COLONY_INTEGRATOR_NAME = "colonyIntegrator"
  5. local OUTPUT_FILE = "colony_orders_report.txt"
  6.  
  7. local colony = peripheral.find(COLONY_INTEGRATOR_NAME)
  8.  
  9. if not colony then
  10. print("ERROR: Colony Integrator ('" .. COLONY_INTEGRATOR_NAME .. "') not found!")
  11. return
  12. end
  13.  
  14. local file = fs.open(OUTPUT_FILE, "w") -- Open in write mode to overwrite/create
  15. if not file then
  16. print("ERROR: Could not open output file: " .. OUTPUT_FILE)
  17. return
  18. end
  19.  
  20. print("Colony Integrator found. Writing data to " .. OUTPUT_FILE .. "...\n")
  21. file.write("Colony Work Order and Resource Report - " .. textutils.formatTime(os.time(), false) .. "\n")
  22.  
  23. local workOrders = colony.getWorkOrders()
  24.  
  25. if not workOrders or #workOrders == 0 then
  26. file.write("No active workOrders found.\n")
  27. print("No active workOrders found.")
  28. file.close()
  29. return
  30. end
  31.  
  32. file.write("Found " .. #workOrders .. " work order(s):\n")
  33. file.write("----------------------------------------\n")
  34. print("Found " .. #workOrders .. " work order(s). See " .. OUTPUT_FILE .. " for details.")
  35.  
  36. for i, wo in ipairs(workOrders) do
  37. file.write("\n--- Work Order #" .. i .. " ---\n")
  38. file.write(" ID: " .. tostring(wo.id) .. "\n")
  39. file.write(" Building Name: " .. tostring(wo.buildingName) .. "\n")
  40. file.write(" Work Order Type: " .. tostring(wo.workOrderType) .. "\n")
  41. file.write(" Target Level: " .. tostring(wo.targetLevel) .. "\n")
  42. file.write(" Is Claimed: " .. tostring(wo.isClaimed) .. "\n")
  43. file.write(" Changed: " .. tostring(wo.changed) .. "\n")
  44. if wo.builder then
  45. file.write(" Builder Location: X:" .. wo.builder.x .. " Y:" .. wo.builder.y .. " Z:" .. wo.builder.z .. "\n")
  46. else
  47. file.write(" Builder Location: N/A\n")
  48. end
  49.  
  50. file.write(" Resources for this Work Order (ID: " .. tostring(wo.id) .. "):\n")
  51. local resources = colony.getWorkOrderResources(wo.id)
  52.  
  53. if resources then
  54. if #resources > 0 then
  55. for resIdx, res in ipairs(resources) do
  56. file.write(" --- Resource #" .. resIdx .. " ---\n")
  57.  
  58. local sResItem = "UnknownItemRegistry"
  59. if type(res.item) == "table" then sResItem = res.item.name or "UnknownInTable" elseif type(res.item) == "string" then sResItem = res.item end
  60. local sResDisplayName = sResItem
  61. if type(res.displayName) == "table" then sResDisplayName = res.displayName.name or sResDisplayName elseif type(res.displayName) == "string" then sResDisplayName = res.displayName end
  62.  
  63. file.write(" Item Registry: " .. sResItem .. "\n")
  64. file.write(" Display Name: " .. sResDisplayName .. "\n")
  65. file.write(" Needed: " .. tostring(res.needed) .. " (Type: " .. type(res.needed) .. ")\n")
  66. file.write(" Available: " .. tostring(res.available) .. " (Type: " .. type(res.available) .. ")\n")
  67. file.write(" Delivering: " .. tostring(res.delivering) .. " (Type: " .. type(res.delivering) .. ")\n")
  68. file.write(" Status: " .. tostring(res.status) .. " (Type: " .. type(res.status) .. ")\n")
  69.  
  70. -- Full dump of the 'res' table to the file
  71. file.write(" Raw 'res' table content for this resource:\n")
  72. for k, v in pairs(res) do
  73. file.write(" " .. tostring(k) .. ": " .. tostring(v) .. " (Type: " .. type(v) .. ")\n")
  74. end
  75. end
  76. else
  77. file.write(" No specific resource entries listed for this work order.\n")
  78. end
  79. else
  80. file.write(" Failed to retrieve resources for this work order (getWorkOrderResources returned nil).\n")
  81. end
  82. file.write("----------------------------------------\n")
  83. end
  84.  
  85. file.write("\nDiagnostic scan complete.\n")
  86. file.close()
  87. print("Diagnostic data written to " .. OUTPUT_FILE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement