Jump to content




[Request] I need somebody to make a working monitor program


10 replies to this topic

#1 LDDestroier

  • Members
  • 1,090 posts
  • LocationACDC Town

Posted 22 January 2015 - 10:35 PM

I have found that 'Mirror', a program made by wojbie, does not work in CC 1.64. If there isn't a program that outputs a program to both the screen and a monitor, could someone quickly create one for me? I'm trying to make a tron arena.

#2 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 22 January 2015 - 11:05 PM

If you are not using any peripherals then you can just use "monitor <side> <program> <arguments>"
If you are using a wired one, you can pick up its name when you activate the monitor and activate from there.
If you are using wireless then ,from what I know, you need a computer attached to it.
Now, can you be specific on how you are setting up your monitors such as are you using a central computer attached to a bunch of monitors or do you have computers attached to monitors and how do you want to set it up?

#3 LDDestroier

  • Members
  • 1,090 posts
  • LocationACDC Town

Posted 23 January 2015 - 03:19 AM

I want to connect a monitor to the back of an advanced computer, and I want the program to be outputted not only onto the monitor (as if I used the 'monitor' command), but ALSO on the screen that you see when you right click the computer. I'd like it to have the same syntax as the 'monitor' command. It will not be connected through wires.

#4 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 23 January 2015 - 10:09 PM

Ah ok then.
Well, you can use the Peripheral API and Monitor API to do this and just update both screens.
monitor = peripheral.wrap("Back")
monitor.write("Hello world!")
term.write("Hello world!")
This is just a simple hello program displayed on both the monitor and the computer.
All you got to do is wrap it, then copy the command and display.
So if you wanted it to display this simple character:
monitor = peripheral.wrap("back")
monitor.write("^")
term.write("^")
[Note]
The Monitor API is really just the term API except using monitor.whateverCommand instead of term.whateverCommand

Edited by cptdeath58, 23 January 2015 - 10:16 PM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 24 January 2015 - 01:19 AM

Come to think about it, I wrote something along those lines not so long ago. If tweaked like so:

local monitors = {peripheral.find("monitor")}  -- "find" needs CC 1.6 or later

do
	local multiTerm, oldTerm = {}, term.current()
	for funcName,_ in pairs(monitors[1]) do
		multiTerm[funcName] = function(...)
			for i=1,#monitors do monitors[i][funcName](unpack(arg)) end
			if oldTerm[funcName] then return oldTerm[funcName](unpack(arg)) end
		end
	end
	term.redirect(multiTerm)
end

term.clear()
term.setCursorPos(1,1)
print("Hello world!")

... then everything written by the rest of the script should go to the main display in addition to any attached monitors.

Edit: Tweaked in a bugfix, per the below discussion.

Edited by Bomb Bloke, 18 May 2016 - 08:02 AM.


#6 LDDestroier

  • Members
  • 1,090 posts
  • LocationACDC Town

Posted 26 January 2015 - 07:52 PM

Nope, it just errors. It waits for a while, then outputs the following error:
nil: vm error:
java.lang.ArrayIndexOutOfBoundsException
Press any key to continue

I do put that at the beginning of a program, right?

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,451 posts

Posted 26 January 2015 - 10:09 PM

View PostBomb Bloke, on 24 January 2015 - 01:19 AM, said:

Come to think about it, I wrote something along those lines not so long ago. If tweaked like so:

local monitors = {peripheral.find("monitor")}  -- "find" needs CC 1.6 or later

do
	local multiTerm, oldTerm = {}, term
	for funcName,_ in pairs(monitors[1]) do
		multiTerm[funcName] = function(...)
			for i=1,#monitors do monitors[i][funcName](unpack(arg)) end
			if oldTerm[funcName] then return oldTerm[funcName](unpack(arg)) end
		end
	end
	term.redirect(multiTerm)
end

term.clear()
term.setCursorPos(1,1)
print("Hello world!")

... then everything written by the rest of the script should go to the main display in addition to any attached monitors. I think.

You've got a return in there that would prevent it from displaying on more than one device, and using term as the base instead of term.current() or term.native is likely the result of the error displayed above (call term.x, it does your code, then calls term.x, which does your code...).

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 27 January 2015 - 12:52 AM

That return statement isn't where you think it is, and even if there was any recursion (which I'm doubting), it's performed via a tailcall and so it shouldn't trigger a stack overflow. Hmm. Unless term.redirect() doesn't build a new term table... Come to think of it, that's indeed probably it.

Try:

local multiTerm, oldTerm = {}, term.current()

Edited by Bomb Bloke, 27 January 2015 - 12:56 AM.


#9 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,451 posts

Posted 27 January 2015 - 12:57 AM

Ah, yeah. That's what I get for reading code on my phone. The term problem is still a real thing, though. Since it's gonna use term.x, which looks up the current redirect target, and that'll be your functions. As in, grabbing term before you declare all the functions won't actually get the current redirect target at the time.

#10 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 11 April 2015 - 03:44 PM

Btw, since this thread is getting referenced, the script misses the part, where arg is getting set. Or I'm just overly stupid. someone else should test it

#11 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 12 April 2015 - 12:34 AM

It gets set automatically. :)

local function moo(...)
  print(unpack(arg))
end

moo("Like"," ","this!")






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users