This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mikesaa309's profile picture

rs.getinput false

Started by mikesaa309, 15 June 2013 - 06:21 AM
mikesaa309 #1
Posted 15 June 2013 - 08:21 AM
I'm trying to make a train control system using railcraft and computercraft. Part of it i want some kind of train tracking system so I know where trains are. Using a detector track, a redstone signal is sent to a computer which then sends it through renet to the control computer. Using help from this forum I have a code which will track the train so when it's at a station it says "train is at" then station name. This works fine but i want it to tell me when a train has left a station too i presumed that by using something like "if not rs.getInput then" but this just ends the program also i've tried "if rs.getInput false then" but it does the same thing. Here is the current code with my failed attempt:


–Variables
local stationName = ""
local modemSide = someSide
local rsSide = someSide
local frequence = someFrequence

–Initialisation
rednet.open("left")

–Functions
print("press enter to enter/change station name")
local function waitForKeypress()
while true do
local sEvent, sKey = os.pullEvent()
if sEvent == "key" and sKey == keys.enter then
term.write("Station Name: ")
stationName = read()
end
end
end

local function waitForRs()
while true do
os.pullEvent("redstone")
if rs.getInput("back") then
rednet.send(18, "A train is at "..stationName)
elseif rs.getInput("bac") == false then – why doesn't this work how should it be coded?
rednet.send(18, "train has left "..stationName)
end
sleep(0)
end
end
–Main function

local function main()
parallel.waitForAny(waitForKeypress, waitForRs)
end

–BSoD
local _,err = pcall(main)
if err then
term.clear()
term.setCursorPos(1,3)
print("exit")
print("\n\npress any key to exit…")
while true do
local sEvent = os.pullEvent()
if sEvent == "key" then
term.clear()
term.setCursorPos(1, 1)
error()
end
end
end

I added the comment so you know where in the code the problem is. Thanks for any help.
theoriginalbit #2
Posted 15 June 2013 - 08:32 AM
the problems is because you have done the side as "bac" not "back", however you do not need to check again

if rs.getInput("back") then
  print("rs was on")
else
  print("rs was off")
end

also it should be noted, that just like how you don't need == true you don't need == false, you can just use the not operator.

if not rs.getInput("back") then