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

Help with os.pullEvent()

Started by RoD, 04 July 2013 - 11:34 AM
RoD #1
Posted 04 July 2013 - 01:34 PM
i am having a problem… i want to inculde key pressing to my program but if i do then the progrm cant receive any rednet message.
Here is the code so far:

shell.run("clear")
rednet.open("right")
print"Welcome to turtle controller by RoD!"
while true do
event, scancode = os.pullEvent("key")
if (tostring(scancode)) == "17" then
rednet.send(15, "w", true)
elseif (tostring(scancode)) == "30" then
rednet.send(15, "a", true)
elseif (tostring(scancode)) == "31" then
rednet.send(15, "s", true)
elseif (tostring(scancode)) == "32" then
rednet.send(15, "d", true)
elseif (tostring(scancode)) == "57" then
rednet.send(15, "space", true)
elseif (tostring(scancode)) == "42" then
rednet.send(15, "shift", true)
shell.run("clear")
shell.run("startup")
else
print("Unrecognised command")
sleep(2)
shell.run("clear")
shell.run("startup")
end
end
Can someboy say what am i doing wrong pls? :P/>
TeamDman #2
Posted 04 July 2013 - 01:55 PM
Please point to where the program receives a rednet message. I can't find one.
Lyqyd #3
Posted 04 July 2013 - 06:11 PM
Split into new topic.

Please don't resurrect year-old topics to add an unrelated question of your own.
RoD #4
Posted 06 July 2013 - 02:49 PM
Please point to where the program receives a rednet message. I can't find one.
The program has not yet the receiver… i need to add one thats why i need some help, if i want to run the loop that detects if i press a key, i cant receive any message from the turtle. Is there anyway to this?
Lyqyd #5
Posted 06 July 2013 - 03:42 PM
Don't use the "key" filter in your os.pullEvent call, of course.
albrat #6
Posted 07 July 2013 - 11:24 AM

shell.run("clear")
rednet.open("right")
print"Welcome to turtle controller by RoD!"
while true do
event, scancode, mess, dist = os.pullEvent()
if event == "rednet_message" then
-- rednet code messages
-- scancode will contain the ID of the sender of the rednet message
-- mess stores the rednet message
-- dist is the rednet send distance.
elseif event == "key" then
-- your normal code
if (tostring(scancode)) == "17" then
rednet.send(15, "w", true)
elseif (tostring(scancode)) == "30" then
rednet.send(15, "a", true)
elseif (tostring(scancode)) == "31" then
rednet.send(15, "s", true)
elseif (tostring(scancode)) == "32" then
rednet.send(15, "d", true)
elseif (tostring(scancode)) == "57" then
rednet.send(15, "space", true)
elseif (tostring(scancode)) == "42" then
rednet.send(15, "shift", true)
shell.run("clear")
shell.run("startup")
else
print("Unrecognised command")
sleep(2)
shell.run("clear")
shell.run("startup")
end
end
end

that should achieve the thing you are trying to do I hope.
RoD #7
Posted 07 July 2013 - 02:24 PM

shell.run("clear")
rednet.open("right")
print"Welcome to turtle controller by RoD!"
while true do
event, scancode, mess, dist = os.pullEvent()
if event == "rednet_message" then
-- rednet code messages
-- scancode will contain the ID of the sender of the rednet message
-- mess stores the rednet message
-- dist is the rednet send distance.
elseif event == "key" then
-- your normal code
if (tostring(scancode)) == "17" then
rednet.send(15, "w", true)
elseif (tostring(scancode)) == "30" then
rednet.send(15, "a", true)
elseif (tostring(scancode)) == "31" then
rednet.send(15, "s", true)
elseif (tostring(scancode)) == "32" then
rednet.send(15, "d", true)
elseif (tostring(scancode)) == "57" then
rednet.send(15, "space", true)
elseif (tostring(scancode)) == "42" then
rednet.send(15, "shift", true)
shell.run("clear")
shell.run("startup")
else
print("Unrecognised command")
sleep(2)
shell.run("clear")
shell.run("startup")
end
end
end

that should achieve the thing you are trying to do I hope.
Exactly what i was looking for thanks :D/>