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

[Question] computer wont print on redstone input

Started by Mtshaw113, 20 October 2012 - 10:47 PM
Mtshaw113 #1
Posted 21 October 2012 - 12:47 AM
Ok so I have an IC2 Nuclear Reactor running and if you know this, you need a redstone signal for it too run. I have a green RP2 lamp and a red one, red has a not Gate connected so when its running, the red light turns on. I have the wire thats connected to the red lamp in a yellow cable, and I have a white cable thats connected to the green lamp. I connected the 2 with bundled cable and put it into the back of my computer. I also have a monitor set up next to it. What i want, is for the monitor to say "Reactor is ON and dangerous, Caution is advised!!" When the yellow wire is on, and when the white wire is on to say "Reactor is OFF and Safe, Approach at your own risk". I do have some code right now, but it wont print on the monitor or in the computer(when i dont do "monitor left <name>" it should print in the computer, i think)
Code:
while true do
local event = os.pullEvent("redstone")
local White=rs.testBundledInput("back", colors.white)
local Yellow=rs.testBundledInput("back", colors.yellow)
if White then
print " Reactor is OFF and Safe, Approach at your own risk"
elseif Yellow then
print "Reactor is ON and dangerous, Caution is advised!!"
shell.run"clear"
end
end
The shell.run"clear" I dont know what it means but i saw it somewhere and thought it was used for this(im probably wrong) And the computer gives no error, it just wont print. Sorry for all the writing, i was trying to accuratey describe it.
OmegaVest #2
Posted 21 October 2012 - 03:34 AM
shell.run("clear")

You need the parentheses around it. Also, very lag-happy way to do that. Better to use term.clear() and term.setCursorPos(1,1). Also, put a sleep in the while loop. And put the clear at the top, not the bottom. As you have it, this will only show the blank screen, because that is last.
Lyqyd #3
Posted 21 October 2012 - 04:02 AM
Sleep is not necessary, since he's got an os.pullEvent("redstone"), which is certainly the better way to do this. However, the pullEvent and the clear lines should be swapped.
ChunLing #4
Posted 21 October 2012 - 04:23 AM
You don't want to run any kind of clear at the end of your loop, that erases any text you printed in the same frame you printed it. The text is probably printing and you're not seeing it because you're clearing the terminal immediately. Like Lyqyd says, swap those lines.
cheekycharlie101 #5
Posted 21 October 2012 - 05:51 PM
to solve the print issue your simpley missing the brackets. for instance
this is what you have done

print"Hello World"

this is the right way of doing it

print("Hello World")
that should make it print for you
thanks -Cheeky
Lyqyd #6
Posted 21 October 2012 - 05:57 PM
to solve the print issue your simpley missing the brackets. for instance
this is what you have done

print"Hello World"

this is the right way of doing it

print("Hello World")
that should make it print for you
thanks -Cheeky

Technically, when the only argument is a string literal, the parentheses are not required. I'm not certain what effect the lack of a space may have had.
ChunLing #7
Posted 21 October 2012 - 08:18 PM
It's fine, the lua interpreter picks off "print" from the string in quotes just fine, since there is no other valid interpretation. It may not be the best habit, but it works in CC's implementation.