Difference between revisions of "Os.queueEvent"

From ComputerCraft Wiki
Jump to: navigation, search
(Fixing code)
Line 9: Line 9:
 
{{Example
 
{{Example
 
|desc=The program adds an event which it will eventually pull.
 
|desc=The program adds an event which it will eventually pull.
|code=function clear()
+
|code=
 +
function clear()
 
   term.clear()
 
   term.clear()
   term.setCursorPos (1,1)
+
   term.setCursorPos(1,1) end  
end
+
  os.queueEvent("abc", 2, "meow")
os.queueEvent("abc", 2, "meow")
+
  while true do
while true do
+
    local event, param1, param2 = os.pullEvent()
  local event, param1, param2 = os.pullEvent()
+
    if event == "abc" then
  if event == "abc" then
+
        print("ABC EVENT! Parameters: "..param1.." / " ..param2)
      print("ABC EVENT! Parameters: "..param1.." / " ..param2)
+
    else
  else
+
        print("Event: "  .. event )
      print("Event: "  .. event )
+
    end
  end
+
end
end
+
 
}}
 
}}
 
}}
 
}}

Revision as of 10:12, 30 October 2012


Grid Redstone.png  Function os.queueEvent
Adds an event eventName with the specified parameters to the event queue.
Syntax os.queueEvent(string eventName, param1, param2, param3)
Returns nil
Part of ComputerCraft
API os

Examples

Grid paper.png  Example
The program adds an event which it will eventually pull.
Code
function clear()
  term.clear()
  term.setCursorPos(1,1) end 
  os.queueEvent("abc", 2, "meow")
  while true do
   local event, param1, param2 = os.pullEvent()
   if event == "abc" then
       print("ABC EVENT! Parameters: "..param1.." / " ..param2)
   else
       print("Event: "  .. event )
   end
end


Grid paper.png  Example
To easily have a redstone and a key input do the same,
it queues a key event with the appropriate key if a redstone event happens.
Code
while true do
    local event, param1 = os.pullEvent()
    if event == "redstone" then
      if rs.getInput("left") then
        os.queueEvent("key",28)
      end
    elseif event == "key" then
      if param1 == 28 then
        print("Hello")
      end
    end
end