I put
id, mes, prt = rednet.recieve()
_, key = os.pullEvent("key")
but then it will wait for a rednet message and only after it recieves one will it move onto waiting for the keypress.Or could I possibly do this with os.pullEventRaw?
id, mes, prt = rednet.recieve()
_, key = os.pullEvent("key")
but then it will wait for a rednet message and only after it recieves one will it move onto waiting for the keypress.
local event, id, message, protcol = os.pullEvent()
if event == "rednet_message" then
--# do rednet stuff here
elseif event == "key" then
--# do key stuff here
end
Use os.pullEvent() without a filter then use if statements, like so…local event, id, message, protcol = os.pullEvent() if event == "rednet_message" then --# do rednet stuff here elseif event == "key" then --# do key stuff here end
Alright, now I assume the variable that would be assigned as the which key was detected would be id?
Alright, now I assume the variable that would be assigned as the which key was detected would be id?
That would be correct.
rednet_message and modem_message are different events. modem_message does not give you the computer ID, as that is actually part of a rednet packet.
Just did some testing; I am running LurCraft's Relived modpack which is 1.7.10, I guess rednet_message was the wrong one. It is apparently modem_message.
Keyvalues are wierd, but okay. A is 30, b is 48, c is 25…?
if event == "key" and id == keys.a then
if event == "char" and id == "a" then
Running a test, I have found that the version of CraftOS the server is using (1.7) does not run this coroutine(Or was disabled or something) so no matter what, whether it is sent with rednet.broadcast or rednet.send it recieves it, and labels it as modem_message events, without automatically fixing it to be a proper rednet_message. I will have to manually unpack the table.Just did some testing; I am running LurCraft's Relived modpack which is 1.7.10, I guess rednet_message was the wrong one. It is apparently modem_message.
The deal is that all networking is done via modem_message events, but CraftOS runs a coroutine alongside your code which checks for these, and, if it determines they were sent using rednet.send(), generates corresponding rednet_message events (unpacking the table for you for eg). You DO want to work with these rednet_message events, not the original modem_message events.
oh, alright with the keys then. those are working properly now that I got the keymap (And the numbers assigned make sense now lol).Keyvalues are wierd, but okay. A is 30, b is 48, c is 25…?
You can see the map here, but usually you're better off using the keys API. Eg:if event == "key" and id == keys.a then
That's if you simply want to know which buttons were pressed on the keyboard, though. If you want to know which characters were generated, use char events instead:if event == "char" and id == "a" then
Or… extra thought, these rednet_message events are probably generated afterwards aren't they? Wouldn't I then need two os.pullevents?
local event, par1, par2, par3 = os.pullEvent("rednet_message")
while true do
local event, par1, par2, par3 = os.pullEvent()
if event == "rednet_message" then
-- do stuff
elseif event == "key" then
-- do other stuff
end
end
will try this one and let you know.while true do local event, par1, par2, par3 = os.pullEvent() if event == "rednet_message" then -- do stuff elseif event == "key" then -- do other stuff end end
The latter example will pull modem_message events, but the if/then block won't act on them, and the loop will have it simply pull the next event from the queue as soon as it drops in there.