os.pullEvent() Question
#1
Posted 20 January 2013 - 04:59 PM
#2
Posted 20 January 2013 - 05:00 PM
while true do
local event, p1, p2, p3 = os.pullEvent()
if event == "a" then
--do event a stuff
break
elseif event == "b" then
--do event b stuff
break
end
end
Edited by RunasSudo, 20 January 2013 - 05:02 PM.
#3
Posted 20 January 2013 - 05:02 PM
RunasSudo, on 20 January 2013 - 05:00 PM, said:
local event = { os.pullEvent() }
if event[1] == "key" then
local keyCode = event[2]
elseif event[1] == "char" then
local charPressed = event[2]
end
#4
Posted 20 January 2013 - 05:06 PM
TheOriginalBIT, on 20 January 2013 - 05:02 PM, said:
local event = { os.pullEvent() }
if event[1] == "key" then
local keyCode = event[2]
elseif event[1] == "char" then
local charPressed = event[2]
end
It makes other people look silly when they re-state what I edited in.
On topic: Why did you os.pullEvent() to a table? Seems rather superfluous...
Also, your code will continue the program whether or not a valid event was fired.
#5
Posted 20 January 2013 - 05:16 PM
RunasSudo, on 20 January 2013 - 05:06 PM, said:
It makes other people look silly when they re-state what I edited in.
RunasSudo, on 20 January 2013 - 05:06 PM, said:
local event, p1, p2, p3, p4 = os.pullEvent()looks much neater like this
local event = { os.pullEvent() }
And your not loosing any data, its just in a table... also I've found some ppl get confused when there is 4 params declared but they are only using 1 for the thing... in a table, they use how many they want...
RunasSudo, on 20 January 2013 - 05:06 PM, said:
#7
#8
Posted 20 January 2013 - 08:14 PM
#10
Posted 20 January 2013 - 09:39 PM
TheOriginalBIT, on 20 January 2013 - 05:16 PM, said:
TheOriginalBIT, on 20 January 2013 - 07:54 PM, said:
"redstone" has 0, "key" has 1, "mouse_click" has 3 OR
"redstone" has 1, "key" has 2, "mouse_click" has 4.
#11
Posted 20 January 2013 - 09:43 PM
RunasSudo, on 20 January 2013 - 09:39 PM, said:
"redstone" has 0, "key" has 1, "mouse_click" has 3 OR
"redstone" has 1, "key" has 2, "mouse_click" has 4.
#12
Posted 20 January 2013 - 09:49 PM
TheOriginalBIT, on 20 January 2013 - 09:43 PM, said:
Now what was I saying again?
#13
Posted 21 January 2013 - 09:56 AM
TheOriginalBIT, on 20 January 2013 - 05:02 PM, said:
local event = { os.pullEvent() }
if event[1] == "key" then
local keyCode = event[2]
elseif event[1] == "char" then
local charPressed = event[2]
end
Really, you should requeue the event if you didn't handle it, shouldn't you?
local event = {os.pullEvent()}
if event[1] == "key" then
local keyCode = event[2]
elseif event[1] == "char" then
local charPressed = event[2]
else
os.queueEvent(unpack(event))
end
EDIT: No, you definitely should not! The parallel API makes sure that you don't swallow messages expected by other coroutines.
Edited by Eric, 21 January 2013 - 10:22 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











