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

Very new to ComputerCraft, and I'm having trouble doing stuff that's probably really easy

Started by Kairi091, 11 January 2014 - 12:24 PM
Kairi091 #1
Posted 11 January 2014 - 01:24 PM
Here's what I'm trying to do. I want a rednet cable to give a signal to one side of the computer and when it gets that signal (it will only be a brief signal caused by a cart passing over a detector track), I'd like the computer to output several "blinking" signals thru rednet cable on another side to activate and make a few Redstone Lamps blink. I'd also like to have something displayed on a monitor. I know how to manually use the monitor program to run a program on a monitor, but I don't know how to encode displaying text on a monitor as part of a program that will run automatically (by naming it "startup"). Is there anyway to have multiple monitors displaying the same text as the program is running?

Thank you!!
6677 #2
Posted 11 January 2014 - 03:28 PM
rednet cable isn't a thing. I assume you mean network cable, these do not conduct redstone. You need a bundled cable mod or just plain redstone will do for this.

now. As for actually using a monitor. You need to use it as a peripheral, there are several guides for that but I'll drop some quick code in here anyway.


local monitor = peripheral.wrap("right")
This is the important part. All I have done is make a local variable called monitor, peripheral.wrap("right") then takes the peripheral on the right hand side of the computer and stores it in monitor so we can use it. I recommend this line goes near the beginning of your code.

Now. Once you have your monitor, you can use all functions of the term API on it: http://computercraft.info/wiki/Term_(API)
So lets print "Hello World" on the monitor.

monitor.setCursorPos(1,1)
monitor.write("Hello World")

if you want to do the above on 2 monitors:

local monitor1 = peripheral.wrap("left")
local monitor2 = peripheral.wrap("right")
monitor1.setCursorPos(1,1)
monitor2.setCursorPos(1,1)
monitor1.write("Hello World")
monitor2.write("Hello World")

print(), write(), term.setCursorPos() etc will all effect the computer screen as normal and leave the monitor untouched. This allows you to have one interface running on the computer and another on the monitor. However an alternative to the above method is to use a terminal redirect. This is actually what the monitor program does in computercraft. Create your monitor object as above. Then do this:
term.redirect(monitor)
Whenever you use the term API on your computer, print or write it will all be done on the monitor instead of the computer screen. term.restore() undoes this. Its actually really annoying so don't bother doing it.
Another neat trick you can do:

monitor = peripheral.wrap("top")
local function write(input)
    term.write(input)
    monitor.write(input)
end

now if you just call write("hello") it will simultaneously be written to the monitor and computer at once.
Bomb Bloke #3
Posted 11 January 2014 - 05:39 PM
rednet cable isn't a thing.
Tell that to MineFactory Reloaded. It's one of the two types of bundled redstone cables that ComputerCraft supports.
surferpup #4
Posted 11 January 2014 - 06:39 PM
I want a rednet cable to give a signal to one side of the computer and when it gets that signal (it will only be a brief signal caused by a cart passing over a detector track), I'd like the computer to output several "blinking" signals thru rednet cable on another side to activate and make a few Redstone Lamps blink.

This isn't too bad to do. Here is one thought. You could have a single bundled cable attached to the computer. Attach the cable to your detector on the colors.red channel and to your redstone lamp on the colors.orange channel.


while true do
	event = os.pullEvent("redstone") -- will happen when a redstone imput changes
	if rs.testBundledInput("back",colors.red) then
		rs.setBundledOutput("back",0) -- turn off all output
		for i = 1,3 do
			rs.setBundledOutput("back",colors.orange) -- turn on redstone lamps
			os.sleep(1)
			rs.setBundledOutput("back",0) -- turn off redstone lamps
			os.sleep(1)
		end
	end
end