10 posts
Posted 28 March 2014 - 10:00 PM
What about adding a feature which would allow to term.redirect() to an array or a variable?
For example:
-- Case 1: the variable content is replaced with the latest output
local var = ""
term.redirect(var)
-- Case 2: a new entry is added to the array when something is outputted to the term.
local var = {}
term.redirect(var)
Another way to do this could be a term.getOutput() which could return the latest output or a table with all the outputted messages.
1281 posts
Posted 28 March 2014 - 10:19 PM
Facepalm so hard, this is exactly the kinda stuff term.redirect is for…
--case 1
local var = ""
term.redirect(
{
write = function(text)
var = text
end
}
)
--case 2
local var = {}
term.redirect(
{
write = function(text)
var[#var+1] = text
end
}
)
1688 posts
Location
'MURICA
Posted 28 March 2014 - 10:20 PM
I don't see how
local foo = ""
term.redrect(stuff)
term.write("bar")
local foo = {}
term.redirect(foo)
term.write("bar")
is better than
local foo = "bar"
local foo = {}
table.insert(foo, "bar")
Unless I'm misunderstanding the suggestion. What would be the use of this?
8543 posts
Posted 28 March 2014 - 10:40 PM
You'd need to create a full redirect object that placed the written information into a rolling buffer or something, you can't just get away with only having a write function. Also, the latest version of ComputerCraft includes term.current, which returns the current redirect object.
This suggestion can already be implemented in Lua, and has been many times, if not exactly how OP suggests. The new windowing API may well be able to do roughly what you seek.
7508 posts
Location
Australia
Posted 28 March 2014 - 11:13 PM
Here is a
little script I wrote when asking Dan about the new term features so that I could update my treasure disk program, it shows the two valid methods of using the new
term.redirect
10 posts
Posted 29 March 2014 - 10:31 AM
Here is a
little script I wrote when asking Dan about the new term features so that I could update my treasure disk program, it shows the two valid methods of using the new term.redirect
Thanks! This is exactly what I was looking for. I didn't know this usage of term.redirect()…I thought it could only redirect the term to a monitor, I haven't really found any other usage in the wiki.
Facepalm so hard, this is exactly the kinda stuff term.redirect is for…
(code)
There's no reason for being so rude…I've seen a lot of topics with replies like yours. As I already said, I thought that term.redirect() could only redirect the term to a monitor. If I knew how to do that, I wouldn't have started this topic.
7508 posts
Location
Australia
Posted 29 March 2014 - 10:39 AM
Thanks! This is exactly what I was looking for. I didn't know this usage of term.redirect()…I thought it could only redirect the term to a monitor, I haven't really found any other usage in the wiki.
Just be aware that this is only for ComputerCraft 1.6 however. Its slightly different for previous versions, if you want an example for those versions I can write you up one :)/>
10 posts
Posted 29 March 2014 - 12:08 PM
Just be aware that this is only for ComputerCraft 1.6 however. Its slightly different for previous versions, if you want an example for those versions I can write you up one :)/>
It's okay, the code I'm writing needs some 1.6 functions ;)/>