Jump to content




Button Run Program


  • You cannot reply to this topic
2 replies to this topic

#1 Pjevser

  • Members
  • 9 posts

Posted 21 October 2013 - 10: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)

#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 21 October 2013 - 02: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.

#3 Pjevser

  • Members
  • 9 posts

Posted 21 October 2013 - 02:38 PM

ah thanks :)

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users