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

I need help with term.restore()

Started by Nullname123, 07 August 2014 - 04:28 PM
Nullname123 #1
Posted 07 August 2014 - 06:28 PM
Here is my problem when i use term.restore it allways says attempt to call nil.

The code is fine! I think but im not sure.



local F1 = "F1"

m = peripheral.wrap("right")

function B()
term.clear()
term.setCursorPos(1,1)
write("Fraese wird Hochgefahren")
term.setCursorPos(1,2)
write("F1 = Schruben")
term.setCursorPos(1,3)
write("F2 = Schlichten")
term.setCursorPos(1,4)
write("F3 = Abstechen")
term.setCursorPos(1,5)
write("F4 = Innenausdrehen")
term.setCursorPos(1,19)
write("Eingabe: ")
term.setCursorPos(10,19)
end

function clear()
m.clear()
m.setCursorPos(1,1)
end

function r()
term.redirect(peripheral.wrap("right"))
end

clear()
m.write("Fraese ist einsatzbereit")
term.setCursorPos(1,2)

while true do
B()
local input = read()

if input == F1 then
clear()
r()
m.write("Schrub Program wird vorbereitet.")
sleep(0,2)
term.setCursorPos(1,2)
clear()
term.restore()
end

if input ~= F1 then
clear()
B()
m.write("Falsche eingabe")
sleep(1)
clear()
B()
end
end

Sorry the Text is in german but he is not the problem.

I tried a lot of things but it doesn`t work.

it allways says attempt to call nil and it was by the line 46 and there is term.restore()

I hope you can fix this.
Grim Reaper #2
Posted 07 August 2014 - 07:54 PM
term.restore is deprecated in version 1.6. Instead, I believe you can start off your code by grabbing a reference to the current terminal object by writing:

local currentTerm = term.current()
and replacing the call to term.restore() with

term.redirect (currentTerm)
Nullname123 #3
Posted 07 August 2014 - 08:04 PM
Thank you i will test it and i hope it works
Lyqyd #4
Posted 07 August 2014 - 08:20 PM
The new implementation of term.redirect now returns the terminal object in use prior to the redirection, so you can replace your redirects and restores such that they will work in both versions.


local _old = term.redirect(new)

if _old then
  term.redirect(_old)
else
  term.restore()
end
Nullname123 #5
Posted 08 August 2014 - 04:39 PM
ok it worked but i used the version of Grim Reaper Because i don`t understand what the if and else do
can the computer check where the cursor is ?
Lyqyd #6
Posted 08 August 2014 - 04:57 PM
Check out the term API documentation on the wiki. For that specific question, look at term.getCursorPos. Unless you meant the user's mouse cursor(s), in which case check out the mouse_click event documentation. You can't determine where a user's mouse cursor is without them clicking, dragging, or scrolling.