Posted 08 November 2013 - 12:08 PM
I'm trying to write a program that will let me set redstone state remotely using a computer, which will also save the state to a file to be reused when the world reloads. It seems simple, but it just is not working. I have one computer that sends the request, and the one which acts on it.
Here is the code I have for the receiving computer:
And when the sending computer sends, the receiving gets the correct msg and prints it, but instead of printing what the receiving computer told it to, the msg is just blank. Any suggestions?
Here is the code I have for the receiving computer:
rednet.open('top')
main=311
side='bottom'
function printState()
--term.clear()
--term.setCursorPos(0,0)
print('')
print('Boreing 2.0')
if getState() then
print('Batteries: active')
else
print('Batteries: inactive')
end
end
function createFile()
if not fs.exists('config') then
f=fs.open('config','w')
f.writeLine('false')
f.close()
end
end
function getState()
f=fs.open('config', 'r')
local state=f.readLine()
f.close()
return state
end
function saveState(state)
f=fs.open('config', 'w')
f.writeLine(state)
f.close()
end
function setOutput(state, side)
if getState() then
rs.setOutput(side, false)
printState()
elseif not getState() then
rs.setOutput(side, true)
printState()
end
end
function command()
--setOutput(not getState(), side)
rs.setOutput(side, not getState())
while true do
a, id, msg, dist=os.pullEvent('rednet_message')
if id==main then
write(id..' says ')
print(msg)
saveState(not getState())
rednet.send(main, state, true)
end
end
end
printState()
createFile()
command()
And this is the code for the sending computer:
args={...}
rednet.open('top')
print(args[1])
rednet.send(309, args[1], true)
a, id, msg, d=os.pullEvent('rednet_message')
print(msg)
rednet.close('top')
Whenever I have the acting computer running, no matter what the config file says the state is, it is always active.And when the sending computer sends, the receiving gets the correct msg and prints it, but instead of printing what the receiving computer told it to, the msg is just blank. Any suggestions?
Edited on 08 November 2013 - 12:03 PM