Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- inspectField.lua
- -- Read optional field argument
- local fieldName = ...
- -- Wrap the chest on the right
- local chest = peripheral.wrap("right") -- :contentReference[oaicite:0]{index=0} :contentReference[oaicite:1]{index=1}
- if not chest then
- error("No chest peripheral on the right side")
- end
- -- Always inspect slot 1
- local slot = 1
- local item = chest.getItemDetail(slot) -- :contentReference[oaicite:2]{index=2}
- if not item then
- print("No item in slot " .. slot)
- return
- end
- -- If no field requested, list all keys
- if not fieldName then
- print("Fields in item slot " .. slot .. ":")
- for key in pairs(item) do -- :contentReference[oaicite:3]{index=3}
- print("– " .. key)
- end
- return
- end
- -- Attempt to fetch the requested field
- local value = item[fieldName]
- if value == nil then
- error("Field '" .. fieldName .. "' not found on item")
- end
- -- Helper to pretty-print nested tables
- local function dump(v, indent)
- indent = indent or ""
- if type(v) == "table" then
- for k, x in pairs(v) do -- :contentReference[oaicite:4]{index=4}
- -- If it’s an array-like subtable, use ipairs for numeric indices
- if type(x) == "table" then
- print(indent .. k .. ":")
- dump(x, indent .. " ")
- else
- print(indent .. k .. ": " .. tostring(x))
- end
- end
- else
- -- Fallback for numbers/strings/booleans
- print(tostring(v))
- end
- end
- -- Print the requested field
- print("Contents of field '" .. fieldName .. "':")
- dump(value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement