Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local taskQueue = {}
- local function taskToString (task)
- return task.count .. "*" .. task.cmd
- end
- local function addTask (task)
- table.insert (taskQueue, task)
- os.queueEvent ("taskAdd")
- end
- local function pullTask ()
- local task = table.remove (taskQueue, 1)
- while task == nil do
- os.pullEvent ("taskAdd")
- task = table.remove (taskQueue, 1)
- end
- return task
- end
- local function receiver ()
- while true do
- local id, msg, protocol = rednet.receive ()
- local task = textutils.unserialise (msg) or msg
- addTask (task)
- print ("received " .. taskToString (task)
- end
- end
- local function mover ()
- while true do
- local task = pullTask ()
- for i = 1, task.count do
- turtle [task.cmd]()
- end
- print ("moved" .. taskToString (task))
- end
- end
- rednet.open ("back")
- parallell.waitForAny (receiver, mover)
Advertisement
Add Comment
Please, Sign In to add comment