Difference between revisions of "Term.restore"

From ComputerCraft Wiki
Jump to: navigation, search
(Added depreciation notice)
(Elaboration on how term.current() serves to replace term.restore().)
Line 11: Line 11:
 
|api=term
 
|api=term
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Restores the program from running on a monitor to run on the computer
+
|desc=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.<br><br>
 +
 
 +
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|term.current()]] - this can be used to track the previous trail of displays yourself, hence still allowing you to manually [[term.redirect|term.redirect()]] back.
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Restores a program to the computer.  
+
|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.
This will only work if the computer was running a program on a monitor
+
|code= local mon = peripheral.wrap("top")
|code=term.restore()
+
 +
-- 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
 
}}
 
}}
 
|notes=
 
|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, [[term.restore]]() will only restore back to the first redirected monitor.  
+
* 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, use [[term.redirect]]([[term.native]]).
+
* To restore output directly to the terminal in a single step, use [[term.redirect]]([[term.native|term.native()]]).
 
}}
 
}}
  
 
[[Category:API_Functions]]
 
[[Category:API_Functions]]

Revision as of 13:14, 31 March 2014


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, 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.
  • To restore output directly to the terminal in a single step, use term.redirect(term.native()).