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

Two Events in one Function.

Started by RadimBur, 12 November 2014 - 07:34 PM
RadimBur #1
Posted 12 November 2014 - 08:34 PM
Hi, I have a problem with the Event. How do I write code please me there were two Events - mouse click and key event

sorry Google Translator

this is my code:
it is nonfunctional


while true do
local event, key = os.pullEvent("key")

  if key == keys.q then
  os.shutdown ()
  end
local event, button, x, y = os.pullEvent("mouse_click")
xy = x..","..y
if xy == "51,1" and button == 1 then
vypnout ()
break
end
if xy == "51,1" and button == 2 then
restart ()
break
end
if x >= 1 and x <= 4 and y == 1 and button == 1 then
menu ()
break
end
if x >= 42 and x <= 51 and y == 14 and button == 1 then
mainloop ()
break
end
end
Edited on 12 November 2014 - 07:38 PM
KingofGamesYami #2
Posted 12 November 2014 - 08:38 PM
Simply pull all events, by not providing a filter. Then filter them yourself.


local event = { os.pullEvent() }
if event[ 1 ] == "mouse_click" then
  --#do stuff
elseif event[ 1 ] == "key" then
  --#do other stuff
end
RadimBur #3
Posted 12 November 2014 - 08:52 PM
this is nonfunction, too


while true do
local event = { os.pullEvent() }
if event[ 1 ] == "mouse_click" then
if xy == "51,1" and button == 1 then
vypnout ()
elseif xy == "51,1" and button == 2 then
restart ()
elseif x >= 1 and x <= 4 and y == 1 and button == 1 then
menu ()
elseif x >= 42 and x <= 51 and y == 14 and button == 1 then
mainloop ()
end
elseif event[ 1 ] == "key" then
  if key == keys.q then
  os.shutdown ()
  end
end
end
end

http://www.imagehosting.cz/?v=vstiekhdh.png
[img]&lt;a href=[/img]

1405: elseif x >= 1 and x <= 4 and y == 1 and button == 1 then
1406: menu ()
TheOddByte #4
Posted 12 November 2014 - 09:22 PM
Have you actually declared the variables x, y and xy?
RadimBur #5
Posted 12 November 2014 - 09:44 PM
Problem fixed, Thanks you