i'm trying to write a simple rednet chat program using 'os.pullEvent()', i'm trying to set it up so that it waits for the "char" event and the "rednet_message" event. The problem is that it pulls the "key" and "rednet_modem" events first, so is there a way to make it wait for multiple, specific events like 'os.pullEvent("char", "rednet_message")'? or is there a better way of doing all this?
os.pullEvent for multiple, specific events
Started by Morzie, Mar 19 2014 10:10 PM
4 replies to this topic
#1
Posted 19 March 2014 - 10:10 PM
#2
Posted 20 March 2014 - 12:17 AM
local event = {os.pullEvent()}
if event[1] == "char" then
--char code here
elseif event[1] == "rednet_message" then
--rednet code here
end
#4
Posted 20 March 2014 - 04:18 PM
You could also do something like this:
os.pullEventWhitelist = function(...)
local tArgs = {...}
while true do
tEvent = {os.pullEvent()}
if #tArgs < 1 then
return unpack(tEvent)
end
for k, v in ipairs(tArgs) do
if tEvent[1] == tostring(v)then
return unpack(tEvent)
end
end
end
end
then call that like:local event, par1, par2, par3 = os.pullEventWhitelist("key", "char")
Edited by Imred Gemu, 20 March 2014 - 04:20 PM.
#5
Posted 20 March 2014 - 10:26 PM
Imred Gemu, on 20 March 2014 - 04:18 PM, said:
You could also do something like this:
os.pullEventWhitelist = function(...)
local tArgs = {...}
while true do
tEvent = {os.pullEvent()}
if #tArgs < 1 then
return unpack(tEvent)
end
for k, v in ipairs(tArgs) do
if tEvent[1] == tostring(v)then
return unpack(tEvent)
end
end
end
end
then call that like:local event, par1, par2, par3 = os.pullEventWhitelist("key", "char")
Isn't this a bit redundant? Wouldn't you still have to check which type of event it was?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











