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

[Lua] Detecting redstone input

Started by mister_s, 10 July 2012 - 02:21 PM
mister_s #1
Posted 10 July 2012 - 04:21 PM
I've written this LUA program called "cartmanager" basically it manages 2 minecarts in a few ways.
Now, I wanted to create a script that lets both minecarts go at the same time, but it seems that in the end it would require the computer to detect redstone (rail detector) when the 1st minecart goes by.

Could someone show me how to write code to detect redstone input, and then shut the output of a different side of the computer off.

Here's what I have for that specific command

elseif input==both then
print("Preparing. Go into the carts now!")
sleep(6)
print("Sending first cart out...")
sleep(2)
rs.setOutput("left",true)
print("Preparing second cart...")
sleep(0.5)
rs.setOutput("right",true)
sleep(1.5)
rs.setOutput("left",false)
print("Completed! Now waiting for 1st cart...")
I'm hoping that "right",true will become false when it detects redstone input.
xuma202 #2
Posted 10 July 2012 - 04:26 PM
There will be an Event pulled when a Redstone input toggles.

Look here for more information:
http://computercraft...le=Os.pullEvent

Alternatively you can test the input every few ticks.
mister_s #3
Posted 10 July 2012 - 05:13 PM
Oh i see…
I created this:

term.clear()
term.setCursorPos(1,1)
redstone = rs.getInput("bottem") --Creates the detection operation.
out = "+"
both = "-"
help = "?"
print("-------------------------------------------")
print("|CartManager0.4beta by mister_s|")
print("| + to send out a cart					|")
print("|Designed to manage 2 carts!	  |")
print("|For help type ?.						   |")
print("-------------------------------------------")
input = read()
if input==out then
   print("Sending a cart out...")
   sleep(6)
   rs.setOutput("left",true) --Edit the left or right statements to change output of power.
   sleep(0.5)
   rs.setOutput("left",false)
   print("Placing second cart in sending position...")
   rs.setOutput("right",true)
   sleep(1)
   rs.setOutput("right",false)
   print("Thanks for using! Now preparing to reboot...")
   sleep(2)
   os.reboot()
elseif input==both then
   print("Preparing. Go into the carts now!")
   sleep(6)
   print("Sending first cart out...")
   sleep(2)
   rs.setOutput("left",true)
   print("Preparing second cart...")
   sleep(0.5)
   rs.setOutput("right",true)
   sleep(1.5)
   rs.setOutput("left",false)
   print("Completed! Now waiting for 1st cart...")
	    while redstone==true do
	    rs.setOutput("right",false)
	    print("The operation is complete! Rebooting...")
	    os.reboot()
	  end
else
print("So you want help?")
print("CartManager0.4beta is designed to manage 2 carts on the same rail.")
print("Simply create two powered rail slopes, connected together and put minecarts on them.")
print("After you've done that, connect redstone to left and right sides of the computer.")
print("Connect the left redstone with the first sloped rail, and the second with the right.")
print("Now you can create a circut for your carts! Beginning at first slope, and the end at second.")
print("I hoped this helped!")
end
But I get this error,
cartmanager.lua:3:invalid side.
xuma202 #4
Posted 10 July 2012 - 05:33 PM
Spelling error in line 3

redstone = rs.getInput("bottem") --Creates the detection operation.

not bottem but bottom

HINT Sometimes reading the error message is useful
mister_s #5
Posted 10 July 2012 - 06:51 PM
That's embarrasing… thanks.