Difference between revisions of "Term.restore"

From ComputerCraft Wiki
Jump to: navigation, search
(Elaboration on how term.current() serves to replace term.restore().)
(Removed bad advice.)
 
(2 intermediate revisions by one other user not shown)
Line 16: Line 16:
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Wraps a monitor at the top of the computer, then restores back to the previous display. Uses term.restore() ''if available'', or [[term.current|term.current()]] if not.
+
|desc=Wraps a monitor at the top of the computer, redirects to it, then restores back to the previous display. Uses term.restore() ''if available'', or [[term.current|term.current()]] if not.
 
|code= local mon = peripheral.wrap("top")
 
|code= local mon = peripheral.wrap("top")
 
   
 
   
Line 34: Line 34:
 
|notes=
 
|notes=
 
* term.restore() will return the monitor to the last used redirect target - meaning that if you have used [[term.redirect|term.redirect()]] on two different monitor objects, one use of term.restore() will only restore back to the first redirected monitor, whereas a second would restore back to the original display.  
 
* term.restore() will return the monitor to the last used redirect target - meaning that if you have used [[term.redirect|term.redirect()]] on two different monitor objects, one use of term.restore() will only restore back to the first redirected monitor, whereas a second would restore back to the original display.  
* To restore output directly to the terminal in a single step, use [[term.redirect]]([[term.native|term.native()]]).
 
 
}}
 
}}
  
[[Category:API_Functions]]
+
[[Category:Deprecated API Functions]]

Latest revision as of 05:55, 24 August 2015


term.restore has been deprecated.
term.restore has been removed from ComputerCraft in version 1.6.


Grid Redstone.png  Function term.restore
Using versions of ComputerCraft prior to 1.6, this command switches the terminal back to whatever object it was using to output the display prior to the current one. For example, if you redirect from a computer's screen to an attached Monitor, this command will revert back to the computer's own display.

As of version 1.6, ComputerCraft no longer tracks this for you and so term.restore() has been removed. That build instead adds term.current() - this can be used to track the previous trail of displays yourself, hence still allowing you to manually term.redirect() back.
Syntax term.restore()
Returns Nothing
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Wraps a monitor at the top of the computer, redirects to it, then restores back to the previous display. Uses term.restore() if available, or term.current() if not.
Code
local mon = peripheral.wrap("top")

-- If using a build of ComputerCraft without term.restore, record the current terminal output object:
if not term.restore then mon.restoreTo = term.current() end

-- Redirect the terminal to the attached monitor:
term.redirect(mon)

-- Restore back:
if term.restore then
	term.restore()
else
	term.redirect(mon.restoreTo)
end

Additional Notes

  • term.restore() will return the monitor to the last used redirect target - meaning that if you have used term.redirect() on two different monitor objects, one use of term.restore() will only restore back to the first redirected monitor, whereas a second would restore back to the original display.