View difference between Paste ID: qLrx0suR and UxhKgfW8
SHOW: | | - or go back to the newest paste.
1-
local chest = peripheral.wrap("right")
1+
-- inspectField.lua
2-
local item = chest.getItemDetail(1)
2+
3
-- Read optional field argument
4-
  print("No item")
4+
local fieldName = ...
5
6
-- Wrap the chest on the right
7
local chest = peripheral.wrap("right")                                          -- :contentReference[oaicite:0]{index=0} :contentReference[oaicite:1]{index=1}
8-
print("Fields in item slot 1:")
8+
if not chest then
9-
for key in pairs(item) do
9+
  error("No chest peripheral on the right side")
10-
  print("– "..key)
10+
11-
end
11+
12
-- Always inspect slot 1
13
local slot = 1
14
local item = chest.getItemDetail(slot)                                          -- :contentReference[oaicite:2]{index=2}
15
if not item then
16
  print("No item in slot " .. slot)
17
  return
18
end
19
20
-- If no field requested, list all keys
21
if not fieldName then
22
  print("Fields in item slot " .. slot .. ":")
23
  for key in pairs(item) do                                                      -- :contentReference[oaicite:3]{index=3}
24
    print("– " .. key)
25
  end
26
  return
27
end
28
29
-- Attempt to fetch the requested field
30
local value = item[fieldName]
31
if value == nil then
32
  error("Field '" .. fieldName .. "' not found on item")
33
end
34
35
-- Helper to pretty-print nested tables
36
local function dump(v, indent)
37
  indent = indent or ""
38
  if type(v) == "table" then
39
    for k, x in pairs(v) do                                                       -- :contentReference[oaicite:4]{index=4}
40
      -- If it’s an array-like subtable, use ipairs for numeric indices
41
      if type(x) == "table" then
42
        print(indent .. k .. ":")
43
        dump(x, indent .. "  ")
44
      else
45
        print(indent .. k .. ": " .. tostring(x))
46
      end
47
    end
48
  else
49
    -- Fallback for numbers/strings/booleans
50
    print(tostring(v))
51
  end
52
end
53
54
-- Print the requested field
55
print("Contents of field '" .. fieldName .. "':")
56
dump(value)