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

Button Run Program

Started by Pjevser, 21 October 2013 - 09:39 AM
Pjevser #1
Posted 21 October 2013 - 11:39 AM
So i have no idea how to finish it and making it working correctly.

I got a computer and on top of it i got a speaker.

At the moment i have:


if redstone.getInput("left",true) then
 shell.run("myprogram")
end

in myprogram i have:


peripheral.wrap("up").speak("Hey there")

But how do i make so when i press the button (activate the redstone signal) the program will run myprogram?

I have tried with:


while true do
 if redstone.getInput("left",true) then
  shell.run("myprogram")
 end
end

But that ended up repeating the speaker all over and i had to close minecraft completly and open it again before it stopped.

So yeah how to make the program only run myprogram once when i press my button? (btw the button is set on a stone block, so the computer is behind that stone block, so not sure if the button can activate the computer without a redstone beside it on another block)
Engineer #2
Posted 21 October 2013 - 03:22 PM
*shameless self promo, but making use of the AaP Renewal Project*

First, have a read of this events tutorial.
When you have that, it should be very easy to understand this:

while true do
  local e = os.pullEvent( "redstone" ) --# wait for a redstone event, look it up on the wiki!
  if redstone.getInput( "left" ) then
    shell.run( "myprogram" )
  end
end

Dont be scared to read this page, for the redstone API: Linkie!
And if you dont still undrstand what Im doing after the tutorial and the wiki page, dont be afraid to ask us more questions.
Pjevser #3
Posted 21 October 2013 - 03:38 PM
ah thanks :)/>

Now i got a little clever when it comes to computercraft :D/>