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

Computer Adding Extra -UNKNOWN- Command?

Started by Zenon, 28 June 2015 - 02:07 AM
Zenon #1
Posted 28 June 2015 - 04:07 AM
Hia Again :P/> Im Having Issues With My Program, But I Cant Exactly Explain It So Here's My Program


shell.run("WilsonIntro")

function wilson()
term.write("Wilson: ")
local ev, param1, param2 = os.pullEvent()
if param1 == 18 then
  print("Exiting Wilson Program . . .")
  sleep(0.5)
  os.reboot()
elseif param1 == 25 then
  os.pullEvent("char")
  term.write("Program: ")
  input = read()
  tostring(input)
  shell.run(input)
elseif param1 == 46 then
  shell.run("clear")
elseif param1 == 35 then
  shell.run("help")
else
  print("Unrecognized Command. Hit 'h' If You Need Help")
end
end

while true do
wilson()
end

Now, If I Have The Infinite Loop At The End, My Program Will Throw An Extra Command Whenever I Hit Anything And Thus My Computer Will Say "Unrecognized Command. Hit 'h' If You Need Help". (Screenshot) I Dont Even Know How Its Getting The Second Input . . . Any Ideas?
[NOTE]
It Doesnt Do This If I Dont Use An Infinite Loop
Bomb Bloke #2
Posted 28 June 2015 - 04:22 AM
Pushing a character key generates two events - key, followed by char. Try switching this line up the top of your script like so:

local ev, param1, param2 = os.pullEvent("key")

Oh, and make use of the keys API. keys.e, keys.p etc is a lot easier to read than 18, 25 etc.
Zenon #3
Posted 28 June 2015 - 04:37 AM
Aaaah Well, Thanks A Bunch!