Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("left")
- function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- while true do
- id, message = rednet.receive()
- if split(message," ")[1] == "forward" then
- times=tonumber(split(message," ")[2])
- for i=1,times do
- turtle.forward()
- end
- elseif split(message," ")[1] == "up" then
- times=tonumber(split(message," ")[2])
- for i=1,times do
- turtle.up()
- end
- elseif split(message," ")[1] == "down" then
- times=tonumber(split(message," ")[2])
- for i=1,times do
- turtle.down()
- end
- elseif message == "left" then
- turtle.turnLeft()
- elseif message == "right" then
- turtle.turnRight()
- elseif split(message," ")[1] == "back" then
- times=tonumber(split(message," ")[2])
- for i=1,times do
- turtle.back()
- end
- elseif split(message," ")[1] == "shutdown" then
- pc = peripheral.wrap(split(message," ")[2])
- pc.shutdown()
- elseif split(message," ")[1] == "reboot" then
- pc = peripheral.wrap(split(message," ")[2])
- pc.reboot()
- elseif split(message," ")[1] == "turnon" then
- pc = peripheral.wrap(split(message," ")[2])
- pc.turnOn()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement