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

[programs] Running A Program Inside A Box

Started by Dave-ee Jones, 19 November 2013 - 02:56 AM
Dave-ee Jones #1
Posted 19 November 2013 - 03:56 AM
Hello there people!

I was wondering if someone could tell me how to get a program to run inside a smaller box, so you could have about 4 programs running at the same time on the same screen, and how to resize the box and how to make the program run only inside that box, and not go out of it. I really want to know how to do this because I am working on a few programs that require that, so could someone give me some code and explain? Maybe even someone could make a tutorial. I really would love that, and I'm sure I wouldn't be the only one. :)/>

Thanks guys!
Lyqyd #2
Posted 19 November 2013 - 11:12 AM
Create a terminal redirect that limits its available screen space by telling it the new size and ensuring that it only draws to that space, then term.redirect the program to that new redirect target.
Dave-ee Jones #3
Posted 22 November 2013 - 03:45 PM
I thought terminal redirecting was just for redirecting your terminal to different preipherals…I didn't know you could redirect it to different parts of the screen…lol. Major Derp.

So instead of doing something like this:

local m = peripheral.wrap(side)
term.redirect(m)

I could set a table that has the coordinates and the width and height of a box somewhere on the screen and redirect the terminal to that position? Something like this?

local tBox = {
  x = 10
  y = 4
  w = 31
  h = 11
}
term.redirect(tBox)
I know that wouldn't work but I get the idea. How would I make the table/variables for the redirected box and how would I actually use the term.redirect() function with the variables?

Sorry, I'm a noob when it comes to this :P/>
That's why I'm asking.
jay5476 #4
Posted 22 November 2013 - 04:25 PM
I thought terminal redirecting was just for redirecting your terminal to different preipherals…I didn't know you could redirect it to different parts of the screen…lol. Major Derp.

So instead of doing something like this:

local m = peripheral.wrap(side)
term.redirect(m)

I could set a table that has the coordinates and the width and height of a box somewhere on the screen and redirect the terminal to that position? Something like this?

local tBox = {
  x = 10
  y = 4
  w = 31
  h = 11
}
term.redirect(tBox)
I know that wouldn't work but I get the idea. How would I make the table/variables for the redirected box and how would I actually use the term.redirect() function with the variables?

Sorry, I'm a noob when it comes to this
That's why I'm asking.
Im not to sure on this either but basically what you have is a table of all term functions like so

  object = {
    term.write = function()
	  --do stuff here so that term.write only writes in that area
    end
    -- and make sure to make the rest of the functions
  }
then you do

term.redirect(object)
then it will be using object.write instead of default term.write without having to override it
AgentE382 #5
Posted 22 November 2013 - 04:35 PM
That's basically how it would work. But, why write all that complicated code when someone else did already? Check out GopherAtl's Redirect API for a ready-made solution to your problem.