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

Outputting to a Monitor or Terminal

Started by Lost Ninja, 10 June 2013 - 07:30 AM
Lost Ninja #1
Posted 10 June 2013 - 09:30 AM
I want to send a small message via network cable to a nearby monitor, but I'm stumped on the way to send messages via the cable. When I initially tried I got errrors that the peripheral didn't support those commands (term.clear() & term.setCursorPos()) so I worked out that I was trying to send those commands just to the wired modem and not down the wire.

function monOutput(msg)
	term.redirect(peripheral.wrap(monSide))
	term.clear()
	term.setCursorPos(1,1)
	term.print(pName)
	term.print(textutils.formatTime(os.time(),boolean))
	term.print(msg)
	term.restore()
end

function output(msg)
	if monitor == 1 then
		monOutput(msg)
	else
		term.clear()
		term.setCursorPos(1,1)
		print(textutils.formatTime(os.time(), boolean))
		print(msg)
	end
end

I've had another look at the wiki and realised that I should be using p.callRemote(peripheral name, peripheral method) but I cannot work out how to use it in the above code. Do I have to send a callRemote() for each of the commands, or is there some way to wrap it so I can do it once?

edit: derp derp derp… :/
Also I need an easy method to return the monitor name so that when I initialise the program I can store that name in the ini. When I called the correct API function I got a table string which is less than helpful.

Calling the p.getMethodsRemote() instead of p.getNamesRemote() will of course return a table instead of a string… :/
Edited on 10 June 2013 - 10:27 AM
LBPHacker #2
Posted 10 June 2013 - 09:49 AM
The monitor's name (that you wrap or that you redirect the terminal to) is the name given by the wired modem on activation (right click). I mean, you place a wired modem on the monitor, right click on it and it says something like "monitor_0" registered. In that case, the monitor's name is not left or right, but monitor_0.
Lost Ninja #3
Posted 10 June 2013 - 12:34 PM
OP changed to reflect my idiocy… :/

The program is to build a simple (yet complex) TE battery monitor that can intuitively monitor the battery (via MiscPeriphs) and turn on/off engines. Because I loathe actually changing the guts of TE engines to function the same as BC/Foresty/etc engines (eg redstone signal on = engine on) it is designed to work either way on (it doesn't work well with mixed engines ofc). The output() functions above are merely to send an message to a monitor so I don't have to leave access to the computer which is often obscured.

However above and beyond that I prefer to have my oft used code (like this output() function) work under many scenarios, eventually it will go into my internal API so I can use it in all my programs. (Actually the output() function is in fact in that API, I want to expand it to allow for external monitors however.
LBPHacker #4
Posted 10 June 2013 - 12:51 PM
So… My time to be kinda idiot… Is it solved then?
Lost Ninja #5
Posted 10 June 2013 - 05:57 PM
Uh:

How do I send output to a monitor connecting through a cable (as opposed to dire3ctly connecting). Bearing in mind I want to send the entirety of the term. section of the monOutput() function in the above code.

I guess that I can send each line separately with the p.callRemote(peripheral name, peripheral method) so I could use a:

p.callRemote(monitor_1,term.clear())

Or something, but I figured that there is an easier method (or something that works).
Engineer #6
Posted 10 June 2013 - 06:04 PM
When you activate the cable with the monitor, it tells you the name. After that you can simply wrap to that name and redirect the monitor with that.

And for your information; if you can call it, you can wrap it too.