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

Train Station Display Issue

Started by iKnight, 21 September 2016 - 02:09 PM
iKnight #1
Posted 21 September 2016 - 04:09 PM
So you want that when a train stops on a detector rail, that the redstone signal then goes into a computer and then that puts text onto a monitor if the train is there or not? You could use

local x = rs.getInput("<side>") --# this checks the side you specify for what it's current state is, on or off. change side to the side that the redstone is coming in on
and then put

if x then --# if redstone is on
  print("train is here") --# you'd need to edit these for monitors, this is just the detection
else --# if the redstone is off
  print("No train...")
end
if you want it to always happen and only update when the redstone changes you could do this

while true do --# causes the code to come back to here whenever it reaches the end
  os.pullEvent("redstone") --# will stop until redstone around the computer changes state
  if rs.getInput("<side>") then --# if it's on
	--# Train here stuff
  else
	--# Train not here stuff
  end
end


I have used your code and found a display error. When the train leaves the station, the "No train" message is off the screen using a 1x6 monitor.
I defined the monitor at the top, cleared the screen before code is executed, then set the Cursor Position to 1,1. Everything is then printed on the screen.

local mon = peripheral.wrap("<side>") –Defines the side of the monitor
local x = rs.getInput("<side>")

mon.clear() –Clears the monitor
mon.setTextScale(2) –Sets the size of the text
while true do
os.pullEvent("redstone")
if rs.getInput("<side>") then
mon.clear()
mon.setCursorPos(1,1)
mon.write("The Train Has Arrived…")
else
mon.clear()
mon.setCursorPos(1,1) –Sets the location of the cursor
mon.write("Awaiting Train")
end
end
Lyqyd #2
Posted 21 September 2016 - 05:35 PM
This topic was split from here.