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

How To Clear USER Input

Started by Zenon, 27 June 2015 - 06:21 PM
Zenon #1
Posted 27 June 2015 - 08:21 PM
Ok, So Im Attempting To Make A "Wilson Bot". Just Something That Lets You Have A Few Quick Programs, Like Chat Or Reboot, At The Press Of A Key .

Example:
local ev, param1, param2 = os.pullEvent()
if param1 == 18 then –e Key
print("Exiting Wilson Program . . .")
sleep(0.5)
shell.run("clear")
elseif param1 == 25 then –p Key
term.write("Program: ")
input = read()
shell.run(input)
else
print("Unrecognized Command. Hit 'h' If You Need Help")
end

Its Working Great So Far, However If You Press p It Will Execute The term.write() But Will Keep The p Key On Screen.

For Example It Will Print This:
Program: p

Anyone Know How To Delete That p Without The Entire Screen Being Cleared?
KingofGamesYami #2
Posted 27 June 2015 - 08:45 PM
Two events are generated when a person presses, for example, 'p'. One event is the key event (which you are using). The second event is the 'char' event, which the read() function uses. You pull the key event, but leave the char event in queue, where it's pulled by the read() function. Presumably, the user can simply hit backspace to delete the p.

Of course, you don't want the p appearing in the first place, which is easy.


local ev, param1, param2 = os.pullEvent()
if param1 == 18 then --e Key
  print("Exiting Wilson Program . . .")
  sleep(0.5)
  shell.run("clear")
elseif param1 == 25 then --p Key
  term.write("Program: ")
  os.pullEvent( "char" ) --#get rid of the char event still in queue
  input = read()
  shell.run(input)
else
  print("Unrecognized Command. Hit 'h' If You Need Help")
end
Zenon #3
Posted 27 June 2015 - 09:05 PM
Wow, Thanks! Didnt Think It Would Be That Easy Haha.