added scripts
This commit is contained in:
parent
bc0527e651
commit
0cd319935c
18
burn
Normal file
18
burn
Normal file
@ -0,0 +1,18 @@
|
||||
function select_next_item()
|
||||
local sel_pos = 0
|
||||
turtle.select(sel_pos + 1)
|
||||
|
||||
while(turtle.getItemCount() <= 0) do
|
||||
sel_pos = (sel_pos + 1) % 16
|
||||
turtle.select(sel_pos + 1)
|
||||
end
|
||||
end
|
||||
|
||||
while(true) do
|
||||
select_next_item()
|
||||
for i = 1,4,1 do
|
||||
turtle.place()
|
||||
turtle.turnRight()
|
||||
end
|
||||
sleep(20)
|
||||
end
|
47
client
Normal file
47
client
Normal file
@ -0,0 +1,47 @@
|
||||
function dump(o)
|
||||
if o == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
end
|
||||
|
||||
return tostring(o)
|
||||
end
|
||||
|
||||
rednet.open("left")
|
||||
rednet.host("rmm", "t0-turtle01")
|
||||
local master = rednet.lookup("rmm", "master")
|
||||
while true do
|
||||
local event, id, data = os.pullEvent()
|
||||
if event == "rednet_message" then
|
||||
print(id .. " (" .. event .. ")> " .. dump(data))
|
||||
if type(data) == 'table' then
|
||||
if data[1] == 'eval' then
|
||||
local cmd_fn, err = loadstring(data[2])
|
||||
if not cmd_fn then
|
||||
print("Compile error:" .. err)
|
||||
rednet.send(master, "Compile error:" .. err)
|
||||
else
|
||||
local success, output = pcall(cmd_fn)
|
||||
if success then
|
||||
if output then
|
||||
print("Command output: " .. dump(output))
|
||||
rednet.send(master, "Command output: " .. dump(output))
|
||||
end
|
||||
else
|
||||
print("Runtime error:" .. output)
|
||||
rednet.send(master, "Runtime error:" .. output)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
82
control
Normal file
82
control
Normal file
@ -0,0 +1,82 @@
|
||||
function dump(o)
|
||||
if o == nil then
|
||||
return ""
|
||||
end
|
||||
|
||||
if type(o) == 'table' then
|
||||
local s = '{ '
|
||||
for k,v in pairs(o) do
|
||||
if type(k) ~= 'number' then k = '"'..k..'"' end
|
||||
s = s .. '['..k..'] = ' .. dump(v) .. ','
|
||||
end
|
||||
return s .. '} '
|
||||
end
|
||||
|
||||
return tostring(o)
|
||||
end
|
||||
|
||||
function split(s)
|
||||
chunks = {}
|
||||
|
||||
for substring in s:gmatch("%S+") do
|
||||
table.insert(chunks, substring)
|
||||
end
|
||||
return chunks
|
||||
end
|
||||
|
||||
function recv()
|
||||
while true do
|
||||
local id, data = rednet.receive()
|
||||
print("Message from " .. id .. ": " .. dump(data))
|
||||
write("> ")
|
||||
end
|
||||
end
|
||||
|
||||
function move_control(turtle_id)
|
||||
while true do
|
||||
local event, param = os.pullEvent("key")
|
||||
if event == "key" then
|
||||
-- print("Got key: " .. param)
|
||||
if param == 14 then
|
||||
break
|
||||
elseif param == 17 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.forward()"})
|
||||
elseif param == 30 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.turnLeft()"})
|
||||
elseif param == 31 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.back()"})
|
||||
elseif param == 32 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.turnRight()"})
|
||||
elseif param == 57 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.up()"})
|
||||
elseif param == 29 then
|
||||
rednet.send(turtle_id, {"eval", "turtle.down()"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function control()
|
||||
while true do
|
||||
write("> ")
|
||||
local input = split(read())
|
||||
-- print(dump(input))
|
||||
if input[1] == 'lookup' then
|
||||
print(rednet.lookup("rmm", input[2]))
|
||||
elseif input[1] == 'eval' then
|
||||
rednet.send(tonumber(input[2]), {"eval", input[3]})
|
||||
elseif input[1] == 'move' then
|
||||
move_control(tonumber(input[2]))
|
||||
else
|
||||
print("Unknown command")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rednet.open("back")
|
||||
rednet.host("rmm", "master")
|
||||
|
||||
while true do
|
||||
parallel.waitForAny(recv, control)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user