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

How Can You Get Whats On The Screen

Started by jay5476, 10 August 2013 - 02:08 AM
jay5476 #1
Posted 10 August 2013 - 04:08 AM
hello, im wondering how to get all the text that's on the screen like in the screen capture programs made, I have tried looking through the code but found nothing
Bubba #2
Posted 10 August 2013 - 11:21 AM
Well in order to do this you'll have to use function overriding. Function overriding is where you take a function, save it in a variable, and then override the old function with a new one.

In order to get all the text on the screen, you'll have to override term.write with your own function that somehow saves the information. Here's my example:

oldWrite = term.write --# First off we need to save term.write in a variable so we can still use it

storage = {} --# Here is where we can keep everything written to the screen

term.write = function(input) --# Now we're overriding the old variable
  table.insert(storage, input) --# Now we're saving the input to storage
  oldWrite(input) --# And go ahead and use the old function to actually write to the screen
end

If you run the above program, you will begin capturing all text input in the storage table. In order to see the information, you can go into the lua prompt and type "table.concat(storage,',')". This will take all of the stuff in the storage table and write it to the screen, separating each element with a comma.
jay5476 #3
Posted 10 August 2013 - 05:07 PM
do I do the same with print ?
Bubba #4
Posted 10 August 2013 - 06:34 PM
do I do the same with print ?

Nope. Print uses term.write.
Lyqyd #5
Posted 10 August 2013 - 08:48 PM
Of course, this won't tell you where on the screen it is, or when it was put on the screen, or if the screen was cleared or scrolled. To get all of that information, you'd want to create a redirect table with functions that record all of the term calls.
jay5476 #6
Posted 11 August 2013 - 06:16 AM
okay im using a code and it is completely bugging out(some startup:5parallel:22), code can be found here: pastebin.com/cr3k9uru
CometWolf #7
Posted 11 August 2013 - 06:25 AM
your table insert is in the wrong order. It should be (table, insertobject)

w = term.write
stor = {}
term.write = function(inp)
  table.insert(stor, inp)
  w(inp)
end
immibis #8
Posted 11 August 2013 - 08:21 AM
How screen capture programs work is by replacing all the term functions, so anything that writes to the screen calls their functions instead.
Then they record it in a file, and also call the real term functions (so you can see what you're doing).
All screen access eventually calls a term function, even print and write.