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

Is there a blacklist for os.pullEvent()

Started by gril002, 07 April 2016 - 04:00 PM
gril002 #1
Posted 07 April 2016 - 06:00 PM
So I am using os.pullEvent() for touch screen, but I also have to prevent people from terminating my program. If I use os.pullEvent = os.pullEventRaw then the touch screen does not work. So can I just have it so it completely ignores the terminate command?
Bomb Bloke #2
Posted 07 April 2016 - 07:42 PM
os.pullEventRaw will always return terminate events, no matter what filter you set. When you say your "touch screen does not work", I assume you mean "your script crashes when hitting terminate", in which case your fix is to have your code check that your received event data represents a monitor_touch event was received before trying to treat it like a monitor_touch event.

Post your code if you're still stuck.
KingofGamesYami #3
Posted 07 April 2016 - 08:16 PM
You could modify os.pullEvent to ignore "terminate" events.


local unpack = unpack or table.unpack --#compatibility with 5.1 & 5.2
os.pullEvent = function( sFilter ) --#override os.pullEvent
  local result
  repeat --#pull a raw event until the returned event is not terminate
    result = {os.pullEventRaw( sFilter )}
  until result[ 1 ] ~= "terminate"
  return unpack( result )
end
gril002 #4
Posted 07 April 2016 - 08:27 PM
ok tnx helped a lot