Jump to content




[Question] detect a redstone input


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

#1 Finnvos123

  • Members
  • 22 posts

Posted 10 September 2012 - 07:32 PM

I don't understand how to make the computer execute code when a redstone or bundled input is detected.. For example you're running a program on a monitor that has to print stuff when certain colored wires are activated, how would I do that?

#2 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 10 September 2012 - 08:18 PM

Try:
if rs.getBundledInput("colors.clear") then
end

And see how that works.

#3 GopherAtl

  • Members
  • 888 posts

Posted 10 September 2012 - 09:21 PM

you really want to write this as an event-based program using os.pullEvent(), there's an example program on the wiki. You'll listen for the event "redstone" and then check the signal with redstone.getBundledInput, something like this.

Not at a computer with Minecraft/CC right now, so can't test this, but this code ought to work?

--simple example, prints "Red On" or "Red off" whenever red changes states

--loop forever - terminate with ctrl-t
while true do

  --wait for a redstone event.
  local event = os.pullEvent("redstone")

  --test the red input wire
  local redState=rs.testBundledInput("back",colors.red)

  --if redState is true (red wire is on)...
  if redState then
    print("Red on")
  else
    print("Red off")
  end
end



Spoiler


#4 Lettuce

  • Members
  • 210 posts
  • LocationIn your fridge.

Posted 10 September 2012 - 11:57 PM

View PostGopherAtl, on 10 September 2012 - 09:21 PM, said:

you really want to write this as an event-based program using os.pullEvent(), there's an example program on the wiki. You'll listen for the event "redstone" and then check the signal with redstone.getBundledInput, something like this.

Not at a computer with Minecraft/CC right now, so can't test this, but this code ought to work?

--simple example, prints "Red On" or "Red off" whenever red changes states

--loop forever - terminate with ctrl-t
while true do

  --wait for a redstone event.
  local event = os.pullEvent("redstone")

  --test the red input wire
  local redState=rs.testBundledInput("back",colors.red)

  --if redState is true (red wire is on)...
  if redState then
	print("Red on")
  else
	print("Red off")
  end
end



Spoiler

rs.testBundledOutput() doesn't exist... check the wiki. This guy can use os.pullEvent(), but it holds the computer up until it receives redstone input. That can be useful, depending on the program, so be aware of that, Finnvos123. I saw the spoiler, GopherAtl, so I won't shorten it, you're right, it is easier to read.

I hope we helped! :D/>

#5 GopherAtl

  • Members
  • 888 posts

Posted 11 September 2012 - 12:08 AM

Oops, that was a mistake, it's testBundledInput. In this context testing output wouldn't make sense even if it existed!
wait, I said testBundledInput, not testBundledOutput, noticed when I went to edit the original post to fix it. It may not exist, but I just checked the wiki, and it says it does exist. Is it mistaken? Not at a comp with mc/cc still, so can't check...
either way, yeah, if you meant you wanted a program to run constantly, running some code whenever a signal turns on or off, you want the event loop like I showed you, otherwise you'll just do the if test like lettuce suggested.

#6 NIN3

  • New Members
  • 57 posts
  • LocationEverywhere.

Posted 11 September 2012 - 12:15 AM

Erm, thats testBundledImput..... I think your confused, testBundledOutput() does not exsist.

#7 Finnvos123

  • Members
  • 22 posts

Posted 11 September 2012 - 12:48 PM

Thanks!
It helped alot.
When I've got time I'll test a bit.

#8 Finnvos123

  • Members
  • 22 posts

Posted 13 September 2012 - 02:19 PM

Ok, it works.
Now the second question: How to make the text bigger?
Here's the code:
while true do
   local event = os.pullEvent("redstone")
   local Red=rs.testBundledInput("back",colors.red)
   local Yellow=rs.testBundledInput("back",colors.yellow)
   local Orange=rs.testBundledInput("back",colors.orange)
   local Blue=rs.testBundledInput("back",colors.blue)
   if Red then
   print "Red"
   elseif Yellow then
   print "Yellow"
   elseif Orange then
   print "Orange"
   elseif Blue then
   shell.run"clear"
   end
end


#9 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 13 September 2012 - 03:02 PM

Text can only be made bigger on mons i think. (might be wrong)

#10 Finnvos123

  • Members
  • 22 posts

Posted 13 September 2012 - 08:23 PM

That's why I'm asking.
how to make the text on the monitor bigger.
:)/>

#11 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 13 September 2012 - 08:33 PM

You might be able to use term.setTextSize(#), but I have never tried that.... You might get an error. Usually it would be mon.setTextSize(#)

#12 cheekycharlie101

  • Members
  • 231 posts

Posted 08 November 2012 - 07:38 PM

View PostCranium, on 13 September 2012 - 08:33 PM, said:

You might be able to use term.setTextSize(#), but I have never tried that.... You might get an error. Usually it would be mon.setTextSize(#)
its actually mon.setTextScale(#)

#13 cheekycharlie101

  • Members
  • 231 posts

Posted 08 November 2012 - 07:44 PM

View PostFinnvos123, on 13 September 2012 - 08:23 PM, said:

That's why I'm asking.
how to make the text on the monitor bigger.
:P/>

that part is easy. on the top line of your coder type
mon = periperal.wrap("back") -- change to where your monitor is
this tells the monitor where to format it. so it tells the computer where the monitor is.

now just add to your code this

mon.setTextScale(0.5)
make sure that line is under the peripheral.wrap. here are the text sizes available.
0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5
check this api on the wiki and scroll down to monitors section. you should find all you need there.
just remember to use peripheral.wrap or otherwise it will not work.
also use mon.setCursorPos(x,y)
to change where it will print.
thanks -Cheeky

#14 spysean1499

  • Members
  • 11 posts

Posted 16 March 2013 - 09:15 PM

has anayone made a cinima?USING A ATOMATIC SYSTEM





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users