Here is my COM A code for sending the commands to the COM B.
Spoiler
print ("Quarry And Sorter v.1")
print ("Commands:")
print ("StartQ = Start Quarry - StopQ = Stop Quarry")
print ("----------------------------------------------")
print ("StartS = Start Sorter - StopS = Stop Sorter")
write "Command: "
end
function StartQuarry
rednet.open("right")
rednet.send(2, "StartQuarry")
end
function StopQuarry
rednet.open("right")
rednet.send(2, "StopQuarry")
end
function StartSorter
rednet.open("right")
rednet.send(2, "Startsorter")
end
function StopSorter
rednet.open("right")
rednet.send(2, "Stopsorter")
end
if input == "StartQ" then
StartQuarry ()
else
if input == "StopQ" then
StopQuarry ()
else
if input == StartS then
StartSorter ()
else
if input == StopS then
StopSorter ()
end
Okay for this one there is a couple of things.
-First off on line 7 you have an end. Everything above it is print or writes, none of them need and end so it should be removed.
-Second you're using incorrect if/elseif block syntax. else if in Lua is one word elseif. Proper block syntax is
if a == b then
--do stuff
elseif a == c then
--do someting different
else
--since nothing matches do this
end
You can use as many elseif's as you want, but only 1 if per statement, 1 else(it must be the last one), and 1 end.
-You're missing a read() to capture the users input
-Last you will want to place your prints and if statements in a loop.
COM A Corrected Code:
Spoiler
function StartQuarry() -- added ()'s to the functions
rednet.open("right")
rednet.send(2, "StartQuarry")
end
function StopQuarry()
rednet.open("right")
rednet.send(2, "StopQuarry")
end
function StartSorter()
rednet.open("right")
rednet.send(2, "Startsorter")
end
function StopSorter()
rednet.open("right")
rednet.send(2, "Stopsorter")
end
local function clear() -- added clear function
term.clear()
term.setCursorPos(1,1)
end
while true do -- infinite loop
clear()
print ("Quarry And Sorter v.1")
print ("Commands:")
print ("StartQ = Start Quarry - StopQ = Stop Quarry")
print ("----------------------------------------------")
print ("StartS = Start Sorter - StopS = Stop Sorter")
write "Command: "
local input = read()
if input == "StartQ" then
StartQuarry() -- removed space inbetween function name and ()'s
elseif input == "StopQ" then
StopQuarry()
elseif input == "StartS" then
StartSorter()
elseif input == "StopS" then
StopSorter()
elseif input == "exit" then -- added a break to exit the loop and close the program. I'll let you add it to your menu. You can change the command too.
break
end
end
Here is my COM B code.
Spoiler
local Sorter = "left"
local Quarry = "back"
rednet.open("right")
local id, msg = rednet.recieve ()
if msg == StartSorter then
StartSorter ()
else
if msg == StopSorter then
StopSorter ()
else
if msg == StartQuarry then
StartQuarry ()
else
if msg == StopQuarry then
StopQuarry ()
function StartSorter
print ("Starting Sorter...")
sleep(1)
print("Sorter ON")
redstone.setOutput(Sorter, true)
os.restart ()
end
function StopSorter
print ("Stopping Sorter...")
sleep(1)
print ("Sorter OFF")
redstone.setOutput(Sorter, false)
os.restart ()
end
function StartQuarry
print("Starting Quarry...")
sleep(1)
print("Quarry ON")
restone.setOutput(Quarry, true)
os.restart ()
end
function StopQuarry
print("Stopping Quarry...")
sleep(1)
print("Quarry OFF")
redstone.setOutput(Quarry, false)
os.restart ()
end
Pretty much the same here. One thing that will be an issue with this one is you have your if statement above your functions. Lua reads from the top down just like we do, if it reaches a function call or a variable that isn't declared until later in the code it does not know it exists and will error.
I fixed that and a couple of other things. Read the comments in both corrected codes for more info.
COM B Corrected Code:
Spoiler
local Sorter = "left"
local Quarry = "back"
rednet.open("right")
function StartSorter() -- added ()'s
print("Starting Sorter...")
sleep(1)
print("Sorter ON")
redstone.setOutput(Sorter, true)
--os.reboot() -- changed os.restart() to os.reboot() and actually going to remove these. Leaving the computer in a loop is probably better then constant rebooting. The state that you set your redstone will be set to off on the reboot.
end
function StopSorter()
print("Stopping Sorter...")
sleep(1)
print("Sorter OFF")
redstone.setOutput(Sorter, false)
end
function StartQuarry()
print("Starting Quarry...")
sleep(1)
print("Quarry ON")
restone.setOutput(Quarry, true)
end
function StopQuarry()
print("Stopping Quarry...")
sleep(1)
print("Quarry OFF")
redstone.setOutput(Quarry, false)
end
while true do -- loop it so it will always been listening, will need to ctrl+t to exit program
local id, msg = rednet.receive()
if msg == "StartSorter" then -- added "(double quotes) around the strings
StartSorter() -- removed spaces
elseif msg == "StopSorter" then -- elseif
StopSorter()
elseif msg == "StartQuarry" then
StartQuarry()
elseif msg == "StopQuarry" then
StopQuarry()
end
end
If you use Redpower and have bundled cables I can show you how to use that so you only have to run 1 cable out of the computer and will help clean up your physical setup. Send me a PM if you do and I will help you get it going.