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

Train Monitor Program

Started by X3ME, 11 September 2014 - 04:14 PM
X3ME #1
Posted 11 September 2014 - 06:14 PM
Hey i am looking for a program that displays this message:

Line 2 Track 4
Waiting for Train

and changes to

Line 2 Track 2

Careful Boarding into train

Train is here

when it receives a redstone input from top

Thanks,
Cranium #2
Posted 11 September 2014 - 06:26 PM
Do you have any code to show? We can help you write it. Otherwise, if you just want someone to make it for you, I can move this to the General section, as we usually don't do requests.
X3ME #3
Posted 11 September 2014 - 06:39 PM
Hey i am looking for a program that displays this message:

Line 2 Track 4
Waiting for Train

and changes to

Line 2 Track 2

Careful Boarding into train

Train is here

when it receives a redstone input from top

Thanks,

Yes i do:

I have written this: (but it doesnt work)

while true do
os.pullEvent ("redstone")
print ("Line 2 Track 4")
if rs.getInput ("back") then
print ("Line 2 Track 4")
print (" Careful Boarding into train")
print (" Train is Here
shell.run ("test")
end
end
Cranium #4
Posted 11 September 2014 - 07:49 PM
Is this the only code you've written? Because you're right, none of it would work.

while true do
  os.pullEvent("redstone")
  print("Line 2 Track 4")
  if rs.getInput("back") then
    print("Line 2 Track 4")
    print(" Careful Boarding into train")
    print(" Train is Here")
    shell.run ("test")
  end
end
This code is nearly exactly what you've written, and shouldn't have any errors, but to me, it seems that you're missing a huge portion of what you'd actually want.
If I read it right, you want it to constantly write "Line 2 Track 4" until it recieves a redstone signal from the top side of the computer.

while true do
  --#Clear the screen at the start of every loop
  term.clear()
  term.setCursorPos(1,1)
  --#Write initial message
  write("Line 2 Track 4")
  --#Wait for an event, and put the parameters into a table
  local events = {os.pullEvent()}
  --#If the event recieved is the one we want, continue to the rest of the code, else restart the loop
  if events[1] == "redstone" and events[2] == "top" then
    --#Write secondary message
    term.setCursorPos(1,1)
    --#"\n" is the new line indicator. You can use this to have the terminal automatically start a new line after this indicator.
    write("Line 2 Track 2\nTrain has arrived. Please be careful boarding the train")
    shell.run("test")
    --#I'm not sure what "test" is, but if it's the name of this program you're running,
    --#then I'd suggest to not have this line, and instead have your program labelled as "startup"
  end
end
This should be a bit better for what you want.
X3ME #5
Posted 11 September 2014 - 11:08 PM
Thanks. I am mobile but i will try it ASAP