removed concept of a master
This commit is contained in:
parent
132e7e4746
commit
9bd6cd94c8
@ -1,3 +1,5 @@
|
|||||||
|
local hostname = "pocket_computer" .. os.getComputerID()
|
||||||
|
|
||||||
redstone_toggle_id = 50
|
redstone_toggle_id = 50
|
||||||
de_store_mon_id = nil
|
de_store_mon_id = nil
|
||||||
|
|
||||||
@ -91,7 +93,7 @@ for i = 1, #sides do
|
|||||||
end
|
end
|
||||||
|
|
||||||
rednet.open(modemSide)
|
rednet.open(modemSide)
|
||||||
rednet.host("rmm", "master")
|
rednet.host("rmm", hostname)
|
||||||
|
|
||||||
parallel.waitForAny(poll, recv, key_watcher)
|
parallel.waitForAny(poll, recv, key_watcher)
|
||||||
rednet.close(modemSide)
|
rednet.close(modemSide)
|
||||||
|
@ -27,36 +27,36 @@ function recv()
|
|||||||
local cmd_fn, err = loadstring(data[2])
|
local cmd_fn, err = loadstring(data[2])
|
||||||
if not cmd_fn then
|
if not cmd_fn then
|
||||||
print("Failed to compile '" .. data[2] .. "': " .. err)
|
print("Failed to compile '" .. data[2] .. "': " .. err)
|
||||||
rednet.send(master, "Failed to compile '" .. data[2] .. "': " .. err)
|
rednet.send(id, "Failed to compile '" .. data[2] .. "': " .. err)
|
||||||
else
|
else
|
||||||
local success, output = pcall(cmd_fn)
|
local success, output = pcall(cmd_fn)
|
||||||
if success then
|
if success then
|
||||||
if output then
|
if output then
|
||||||
print("Command output from '" .. data[2] .. "': " .. dump(output))
|
print("Command output from '" .. data[2] .. "': " .. dump(output))
|
||||||
rednet.send(master, "Command output from '" .. data[2] .. "': " .. dump(output))
|
rednet.send(id, "Command output from '" .. data[2] .. "': " .. dump(output))
|
||||||
else
|
else
|
||||||
print("There is no command output from '" .. data[2] .. "'")
|
print("There is no command output from '" .. data[2] .. "'")
|
||||||
rednet.send(master, "There is no command output from '" .. data[2] .. "'")
|
rednet.send(id, "There is no command output from '" .. data[2] .. "'")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("Runtime error: " .. output)
|
print("Runtime error: " .. output)
|
||||||
rednet.send(master, "Runtime error: " .. output)
|
rednet.send(id, "Runtime error: " .. output)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif type(data) == 'string' then
|
elseif type(data) == 'string' then
|
||||||
if data == 'ping' then
|
if data == 'ping' then
|
||||||
print("Pong!")
|
print("Pong!")
|
||||||
rednet.send(master, "Pong!")
|
rednet.send(id, "Pong!")
|
||||||
elseif data == 'toggle' then
|
elseif data == 'toggle' then
|
||||||
local output_state = not redstone.getInput("back")
|
local output_state = not redstone.getInput("back")
|
||||||
redstone.setOutput("back", output_state)
|
redstone.setOutput("back", output_state)
|
||||||
print("Toggled output to: " .. tostring(output_state))
|
print("Toggled output to: " .. tostring(output_state))
|
||||||
rednet.send(master, "Toggled output to: " .. tostring(output_state))
|
rednet.send(id, "Toggled output to: " .. tostring(output_state))
|
||||||
elseif data == 'get_state' then
|
elseif data == 'get_state' then
|
||||||
local output_state = redstone.getInput("back")
|
local output_state = redstone.getInput("back")
|
||||||
print("Output state: " .. tostring(output_state))
|
print("Output state: " .. tostring(output_state))
|
||||||
rednet.send(master, {'output_state', output_state})
|
rednet.send(id, {'output_state', output_state})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,7 +72,6 @@ function lever_input()
|
|||||||
local output_state = not redstone.getInput("back")
|
local output_state = not redstone.getInput("back")
|
||||||
redstone.setOutput("back", output_state)
|
redstone.setOutput("back", output_state)
|
||||||
print("Toggled output to: " .. tostring(output_state))
|
print("Toggled output to: " .. tostring(output_state))
|
||||||
rednet.send(master, "Toggled output to: " .. tostring(output_state))
|
|
||||||
end
|
end
|
||||||
sleep(1)
|
sleep(1)
|
||||||
end
|
end
|
||||||
@ -88,7 +87,6 @@ end
|
|||||||
|
|
||||||
rednet.open(modemSide)
|
rednet.open(modemSide)
|
||||||
rednet.host("rmm", hostname)
|
rednet.host("rmm", hostname)
|
||||||
master = rednet.lookup("rmm", "master")
|
|
||||||
|
|
||||||
parallel.waitForAny(recv, lever_input)
|
parallel.waitForAny(recv, lever_input)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user