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

Started by redstone [lua help]

Started by Drsirdeath, 11 July 2012 - 12:13 PM
Drsirdeath #1
Posted 11 July 2012 - 02:13 PM
I need to create a program for a game im making. its a jumping puzzle and once you hit a button it will activate a countdown on a computer. that countdown will keep the door open but once it hits zero will close the door. Now i may be very noobish at this but i know how to do the countdown and the redstone and all that. except i want to know how i can get a program to activate from a redstone signal.

Also if anyone knows how i can display numbers on a monitor straight from a program without typing

monitor (Direction) [program name]

I really appreaciate the help.
MysticT #2
Posted 11 July 2012 - 02:55 PM
To start with redstone, you can make the program wait for it:

while true do
  os.pullEvent("redstone") -- wait for change in redstone
  if rs.getInput("<side>") then -- check the input on the side you want
	break -- break the loop and start the program
  end
end

-- your program here

For the monitor, you need the peripheral and term apis:

local mon = peripheral.wrap("<side>") -- get the monitor, replace <side> with the side of the monitor
term.redirect(mon) -- redirect the output to the monitor

-- your program here

term.restore() -- restore the output to the terminal
Drsirdeath #3
Posted 11 July 2012 - 06:27 PM
Great it works perfectly! thank you.
Jarle212 #4
Posted 11 July 2012 - 07:42 PM
You could allso use shell.run(programPath) before the brake to make it two programs