This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[Question] detect a redstone input
Started by Finnvos123, 10 September 2012 - 06:32 PMPosted 10 September 2012 - 08: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?
Posted 10 September 2012 - 09:18 PM
Try:
And see how that works.
if rs.getBundledInput("colors.clear") then
end
And see how that works.
Posted 10 September 2012 - 10: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?
…but that's a lot harder to parse to someone new to lua and cc :D/>/>
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
I can hear some of you thinking "that program is sooo long you should do X,Y,Z" and I know. The point here is to teach concepts, not to make the shortest code possible. The whole same thing could be written as…
while true do
os.pullEvent("redstone")
print("Red "..(rs.testBundledInput("back",colors.red) and "on" or "off")
end
…but that's a lot harder to parse to someone new to lua and cc :D/>/>
Posted 11 September 2012 - 12:57 AM
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
I can hear some of you thinking "that program is sooo long you should do X,Y,Z" and I know. The point here is to teach concepts, not to make the shortest code possible. The whole same thing could be written as…while true do os.pullEvent("redstone") print("Red "..(rs.testBundledInput("back",colors.red) and "on" or "off") end
…but that's a lot harder to parse to someone new to lua and cc :D/>/>
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/>/>
Posted 11 September 2012 - 01:08 AM
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.
Posted 11 September 2012 - 01:15 AM
Erm, thats testBundledImput….. I think your confused, testBundledOutput() does not exsist.
Posted 11 September 2012 - 01:48 PM
Thanks!
It helped alot.
When I've got time I'll test a bit.
It helped alot.
When I've got time I'll test a bit.
Posted 13 September 2012 - 03:19 PM
Ok, it works.
Now the second question: How to make the text bigger?
Here's the code:
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
Posted 13 September 2012 - 04:02 PM
Text can only be made bigger on mons i think. (might be wrong)
Posted 13 September 2012 - 09:23 PM
That's why I'm asking.
how to make the text on the monitor bigger.
:)/>/>
how to make the text on the monitor bigger.
:)/>/>
Posted 13 September 2012 - 09: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(#)
Posted 08 November 2012 - 07:38 PM
its actually mon.setTextScale(#)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(#)
Posted 08 November 2012 - 07:44 PM
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
Posted 16 March 2013 - 09:15 PM
has anayone made a cinima?USING A ATOMATIC SYSTEM