Jump to content




term.redirect() to a variable


  • You cannot reply to this topic
7 replies to this topic

#1 Chris54721

  • Members
  • 12 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.

#2 CometWolf

  • Members
  • 1,283 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
  }
)


#3 Kingdaro

    The Doctor

  • Members
  • 1,636 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?

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 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.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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

#6 Chris54721

  • Members
  • 12 posts

Posted 29 March 2014 - 10:31 AM

View Posttheoriginalbit, on 28 March 2014 - 11:13 PM, said:

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.

View PostCometWolf, on 28 March 2014 - 10:19 PM, said:

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.

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 29 March 2014 - 10:39 AM

View PostChris54721, on 29 March 2014 - 10:31 AM, said:

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 :)

#8 Chris54721

  • Members
  • 12 posts

Posted 29 March 2014 - 12:08 PM

View Posttheoriginalbit, on 29 March 2014 - 10:39 AM, said:

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 ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users