Posted 20 June 2016 - 02:43 AM
I am building a server that interprets redstone and rednet signal from two computers and
then returns a redstone/rednet signal to these computers. I am using Bundled Cables as
well as Wireless Redstone, but they are not directly necessary.
There are two files named 'initLeft' and 'initRight' in the server that are used to store the value of the redstone or rednet signal coming from the left or right computers respectively. For some reason the functions pertaining to the right side of the system writes the text 'true' into 'initRight' when being sent 'whiteon' or by typing the text directly into the file, and therefore produces the 'text sucks.' message. I need the file to have either 'whiteon' or 'whiteoff' written in it in order for the rest of the system to work and be read by the functions.
Note 1: This is intended to be running many more functions similar to these at all times, so I can control machines that are l located in my house, from a far away location (including different dimensions).
Note 2: This also functions as a file initialization system which counteracts the fact that computers turn off and forget their redstone signal when the Minecraft Server or singleplayer world is shutdown. This is essential to my build.
Thanks in advance.
–while true do
– receiveRight()
– parallel.waitForAll(setRight, checkLeft)
–end
parallel.waitForAll(receiveRight, receiveLeft, setRight, setLeft)
Code for Left Computer
redSend
redReceive
The code for the right computer is a simple rednet message sender, sending either 'whiteon' or 'whiteoff'.
then returns a redstone/rednet signal to these computers. I am using Bundled Cables as
well as Wireless Redstone, but they are not directly necessary.
There are two files named 'initLeft' and 'initRight' in the server that are used to store the value of the redstone or rednet signal coming from the left or right computers respectively. For some reason the functions pertaining to the right side of the system writes the text 'true' into 'initRight' when being sent 'whiteon' or by typing the text directly into the file, and therefore produces the 'text sucks.' message. I need the file to have either 'whiteon' or 'whiteoff' written in it in order for the rest of the system to work and be read by the functions.
Note 1: This is intended to be running many more functions similar to these at all times, so I can control machines that are l located in my house, from a far away location (including different dimensions).
Note 2: This also functions as a file initialization system which counteracts the fact that computers turn off and forget their redstone signal when the Minecraft Server or singleplayer world is shutdown. This is essential to my build.
Thanks in advance.
Spoiler
function receiveLeft()
dir = 'initLeft'
while true do
os.pullEvent('redstone')
state = rs.testBundledInput('back', colors.white)
file = fs.open(dir, 'w')
file.write(state)
file.close()
sleep(0)
end
end
function setLeft()
dir = 'initLeft'
while true do
file = fs.open(dir, 'r')
text = file.readAll()
if text == 'true' then
rs.setBundledOutput('back',2)
elseif text == 'false' then
rs.setBundledOutput('back',0)
end
sleep(0)
end
end
function receiveRight()
dir = '/initRight'
rednet.open('top')
while true do
event,id,message = os.pullEvent('rednet_message')
file = fs.open(dir, 'w')
file.write(message)
file.close()
sleep(0)
end
end
function setRight()
while true do
dir = '/initRight'
file = fs.open(dir,'r')
text = file.readAll()
file.close()
if text == 'whiteon' then
rs.setBundledOutput('back',2)
elseif text == 'whiteoff' then
rs.setBundledOutput('back',0)
else print('text sucks.')
end
sleep(0)
end
end
–while true do
– receiveRight()
– parallel.waitForAll(setRight, checkLeft)
–end
parallel.waitForAll(receiveRight, receiveLeft, setRight, setLeft)
Code for Left Computer
Spoiler
Main
parallel.waitForAll(function() return shell.run('redSend') end, function() shell.run('redReceive') end)
redSend
while true do
input = ''
input = read()
state = rs.getBundledOutput('back', colors.white)
if input == 'send' and state == 0 then
redstone.setBundledOutput('back', 1)
print('yay')
elseif input == 'send' and state == 1 then
redstone.setBundledOutput('back',0)
end
input = ''
end
redReceive
while true do
state = rs.testBundledInput('back', 2)
if state == false then
--print(state)
rs.setBundledOutput('back',0)
else
--print(state)
rs.setBundledOutput('back', 1)
end
sleep(1)
end
The code for the right computer is a simple rednet message sender, sending either 'whiteon' or 'whiteoff'.
Edited on 20 June 2016 - 04:43 AM