Q
QuiveringT
Guest
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 computer 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 sending the message 'whiteon' or typing it 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: I eventually need many of these functions running at the same time, so I can control machines located in my home base while on Mars, etc but also control them when back home.
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.
Here is a link to my world if with the full system: https://drive.google.com/folderview?id=0B8hAFKF4pBHOQTJaRnlpNFh0Mm8&usp=sharing
There are two files named 'initLeft' and 'initRight' in the server computer 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 sending the message 'whiteon' or typing it 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: I eventually need many of these functions running at the same time, so I can control machines located in my home base while on Mars, etc but also control them when back home.
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.
Here is a link to my world if with the full system: https://drive.google.com/folderview?id=0B8hAFKF4pBHOQTJaRnlpNFh0Mm8&usp=sharing
Code:
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)