Jump to content




Computer Adding Extra -UNKNOWN- Command?


2 replies to this topic

#1 Zenon

  • Members
  • 50 posts

Posted 28 June 2015 - 03: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

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 June 2015 - 03: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.

#3 Zenon

  • Members
  • 50 posts

Posted 28 June 2015 - 03:37 AM

Aaaah Well, Thanks A Bunch!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users