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

[Help] [Lua]os.pullEvent() Help

Started by ChaddJackson12, 05 October 2012 - 12:21 AM
ChaddJackson12 #1
Posted 05 October 2012 - 02:21 AM
Alright, I really need help with this problem that I am having. I want to be able to use 2 different os.pullEvent()'s. The ones that I want to use and how I want to use them go something like this…


repeat
   event, side = os.pullEvent("disk")
   event, key = os.pullEvent("key")
until key == 207 or side == "right"
if key == 207 then
   print("Blah")
   os.sleep(2)
   os.shutdown()
elseif side == "right" then
   print(":(/>/>")
end

Ok, one works, and one doesn't. On my program that I am making, it causes the disk part to work, but when I press the key, (Should be "End") it does absolutely nothing.

Could someone help me to be able to get these to work, or something like this? Thanks, ChaddJackson12.
Fatal_Exception #2
Posted 05 October 2012 - 02:34 AM
local event, param1 = os.pullEvent()
if event == "disk" then
  -- do your disk handling
elseif event == "key" then
  -- do your key handling
end
ChaddJackson12 #3
Posted 05 October 2012 - 02:37 AM
local event, param1 = os.pullEvent()
if event == "disk" then
  -- do your disk handling
elseif event == "key" then
  -- do your key handling
end

Ok thanks, but is there a way to only accept a certain key?
Fatal_Exception #4
Posted 05 October 2012 - 02:37 AM
param1 will contain the keycode. Compare against that in side your key handling.
ChaddJackson12 #5
Posted 05 October 2012 - 02:40 AM
param1 will contain the keycode. Compare against that in side your key handling.

So something like this?

local event, param1 = os.pullEvent()
if event == "disk" and param1 == "right" then
-- stuff
elseif event == "key" and param1 == keynumber then
-- stuff
end
Fatal_Exception #6
Posted 05 October 2012 - 02:45 AM
Exactly.
ChaddJackson12 #7
Posted 05 October 2012 - 02:52 AM
Exactly.

Ok, thank you very much, it helped out a lot :(/>/>