Posted 17 June 2013 - 02:31 PM
so i have a program which works fine when i tested it when the computers where with in like a 10 block radius. The program tells me when a train is at a station as a way to help me control trains in my mc station i'm making. So the station is a fair distance from the control room and so i edited the config file to allow rednet to travel further how ever the program on the sending computer ends when ever i go back to the control room. I'm using teleporters from powercraft to go back and forth so i though maybe thats whats doing it so i flew back but still the same problem. I also tried using world anchors but no avail. also the program will say train has left station but not say its at station but in the test world the program works fine no problem. Heres the code for the sending computer:
–Variables
local stationName = ""
local id = 0
local modemSide = someSide
local frequence = someFrequence
local rsSide = someSide
–Initialisation
rednet.open("left")
–getting the station name
term.write("station name: ")
stationName = read()
–getting the id
term.write("Enter computer ID: ")
id = read()
while not tonumber(id) do
print("Not a number")
id = read()
end
id = tonumber(id)
term.write("Change name press n, press i to change ID")
–Functions
local function changeName()
print("Enter station name: ")
stationName = read()
end
local function changeId()
print("enter computer ID: ")
id = read()
while not tonumber(id) do
print("Not a number")
id = read()
end
id = tonumber(id)
end
local function waitForKeypress()
while true do
local sEvent, sKey = os.pullEvent()
if sEvent == "key" then
if sKey == keys.i then
changeId()
elseif sKey == keys.n then
changeName()
end
end
end
end
local function waitForRs()
os.pullEvent("redstone")
while true do
if rs.getInput("back") then
rednet.send(id,"train is at "..stationName)
os.pullEvent("redstone")
else rednet.send(id, "train has left "..stationName)
os.pullEvent("redstone")
end
sleep(1)
end
end
–Main function
local function main()
parallel.waitForAny(waitForKeypress, waitForRs)
end
–BSoD
local _,err = pcall(main)
if err then
print("Some bad error has occured D:\n\n")
print(" " .. tostring(err) .. " \n\n")
print("press any key to exit…")
while true do
local evt = os.pullEvent()
if evt == "key" then
break
end
end
end
and this is the code for the receiving computer (note it prints to a monitor so i can always see where trains are:
local side = ""
print("side of monitor: ")
side = read()
rednet.open("back")
mon = peripheral.wrap(side)
term.clear()
term.setCursorPos(1, 1)
local function changeSide()
print("Enter monitor side: ")
side = read()
end
local function waitForKeypress()
while true do
local event, param1 = os.pullEvent("char")
if param1 == "n" then
changeSide()
end
end
end
local pos = 1
while true do
local id, message, distance = rednet.receive()
mon.setCursorPos(1, pos)
pos = pos + 1
mon.write(message)
end
local function main()
parallel.waitForAny(waitForKeypress)
end
Also the program for the receiving computer remains running even if i leave the control room but its the program on the sending computer that seems to end without error when ever i leave the station. Why is it doing it?
–Variables
local stationName = ""
local id = 0
local modemSide = someSide
local frequence = someFrequence
local rsSide = someSide
–Initialisation
rednet.open("left")
–getting the station name
term.write("station name: ")
stationName = read()
–getting the id
term.write("Enter computer ID: ")
id = read()
while not tonumber(id) do
print("Not a number")
id = read()
end
id = tonumber(id)
term.write("Change name press n, press i to change ID")
–Functions
local function changeName()
print("Enter station name: ")
stationName = read()
end
local function changeId()
print("enter computer ID: ")
id = read()
while not tonumber(id) do
print("Not a number")
id = read()
end
id = tonumber(id)
end
local function waitForKeypress()
while true do
local sEvent, sKey = os.pullEvent()
if sEvent == "key" then
if sKey == keys.i then
changeId()
elseif sKey == keys.n then
changeName()
end
end
end
end
local function waitForRs()
os.pullEvent("redstone")
while true do
if rs.getInput("back") then
rednet.send(id,"train is at "..stationName)
os.pullEvent("redstone")
else rednet.send(id, "train has left "..stationName)
os.pullEvent("redstone")
end
sleep(1)
end
end
–Main function
local function main()
parallel.waitForAny(waitForKeypress, waitForRs)
end
–BSoD
local _,err = pcall(main)
if err then
print("Some bad error has occured D:\n\n")
print(" " .. tostring(err) .. " \n\n")
print("press any key to exit…")
while true do
local evt = os.pullEvent()
if evt == "key" then
break
end
end
end
and this is the code for the receiving computer (note it prints to a monitor so i can always see where trains are:
local side = ""
print("side of monitor: ")
side = read()
rednet.open("back")
mon = peripheral.wrap(side)
term.clear()
term.setCursorPos(1, 1)
local function changeSide()
print("Enter monitor side: ")
side = read()
end
local function waitForKeypress()
while true do
local event, param1 = os.pullEvent("char")
if param1 == "n" then
changeSide()
end
end
end
local pos = 1
while true do
local id, message, distance = rednet.receive()
mon.setCursorPos(1, pos)
pos = pos + 1
mon.write(message)
end
local function main()
parallel.waitForAny(waitForKeypress)
end
Also the program for the receiving computer remains running even if i leave the control room but its the program on the sending computer that seems to end without error when ever i leave the station. Why is it doing it?