Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- print("Running on a computer. yeet")
- return
- else
- print("Turtle dooting doots.")
- end
- local mod = peripheral.wrap("back")
- local black = 1
- local white = 2
- local tnt = 3
- local myDigit, myPos
- if not mod then
- error("Modem not found... Somehow.")
- end
- mod.open(1)
- local function check(got, want, id)
- id = id or "yea"
- if type(got) ~= want then
- error("Expected " .. want .. " got " .. type(got) .. " (" .. id .. ").", 2)
- end
- end
- local function safecheck(got, want, id)
- id = id or "yea"
- if type(got) ~= want then
- printError("[warn] Expected " .. want .. " got " .. type(got) .. " (" .. id
- .. ").", 2)
- return false
- end
- return true
- end
- local function getItems()
- local self = mod.getNameLocal()
- local chest
- for _, name in ipairs(peripheral.getNames()) do
- if name:find("chest") then
- chest = peripheral.wrap(name)
- break
- end
- end
- if not chest then
- error("Couldn't find chest!")
- end
- chest.pushItems(self, 1, 1, 1)
- chest.pushItems(self, 2, 1, 2)
- chest.pushItems(self, 3, 1, 3)
- end
- local function set(i)
- if i == 4 then
- rs.setOutput("front", true)
- os.sleep(0.2)
- rs.setOutput("front", false)
- return
- end
- if turtle.detect() then turtle.dig() end
- turtle.select(i)
- turtle.place()
- end
- local function getPosition()
- local h = io.open("/POS", 'r')
- local n = h:read()
- local p = h:read()
- h:close()
- return tonumber(n), tonumber(p)
- end
- local function setPosition()
- local h = io.open("/disk/last", 'r')
- local n = h:read()
- local p = h:read()
- h:close()
- h = io.open("/disk/last", 'w')
- h:write(n)
- h:write('\n')
- h:write(p + 1)
- h:close()
- h = io.open("/POS", 'w')
- h:write(n)
- h:write('\n')
- h:write(p + 1)
- h:close()
- end
- local function draw(msg)
- if safecheck(msg.digit, "number", "checktable - digit")
- and safecheck(msg.pos, "number", "checktable - pos")
- and safecheck(msg.tp, "number", "checktable - tp") then
- if myDigit == msg.digit
- and myPos == msg.pos then
- print("This message is for me!")
- set(msg.tp)
- else
- print("This message is not for me.")
- end
- end
- end
- local function main()
- myDigit, myPos = getPosition()
- print("Going into main loop.")
- while true do
- local _, _, _, _, message = os.pullEvent("modem_message")
- print("Recieved a message.")
- if safecheck(message, "table", "Message recieve") then
- print("It is good, draw.")
- draw(message)
- else
- print("Do not draw.")
- end
- end
- end
- main()
Add Comment
Please, Sign In to add comment