355 posts
Posted 15 December 2012 - 10:50 PM
Hello all,
Im kinda being a n00b with rednet, so I was just wondering.
Is there a way to run a program that would just run something, while checking for a rednet message?
Kinda like this:
while true do
if rednet == "Hello" then
print("Hello!")
end
if rednet == "Bye" then
print("Bye")
end
if not rednet then
print("No message received")
end
end
Thanks in advantage.
7508 posts
Location
Australia
Posted 15 December 2012 - 10:55 PM
Hello all,
Im kinda being a n00b with rednet, so I was just wondering.
Is there a way to run a program that would just run something, while checking for a rednet message?
Kinda like this:
while true do
if rednet == "Hello" then
print("Hello!")
end
if rednet == "Bye" then
print("Bye")
end
if not rednet then
print("No message received")
end
end
Thanks in advantage.
try something like this
while true do
event, senderId, message = os.pullEvent()
if event == "rednet_message" then
print(message)
end
end
2088 posts
Location
South Africa
Posted 16 December 2012 - 12:12 AM
Yeah use parallel api:
function yourFunction()
-- blah blah code
end
function waitForMessage()
while true do
e, senderID, message = os.pullEvent("rednet_message")
print(message)
return -- use this if you want the program to stop when it gets a rednet message
end
end
-- Main
parallel.waitForAny( yourFunction, waitForMessage ) -- waitForAny means it will stop when any of the functions returns, use waitForAll if you want it to only stop when all functions return
7508 posts
Location
Australia
Posted 16 December 2012 - 12:31 AM
Yeah use parallel api:
can do that too.
but threading isn't the solution to everything. using os events can be just as much, if not more powerful!
355 posts
Posted 16 December 2012 - 03:06 AM
Hmmm… That is not exactly what I want, because I explained it wrong.
I kinda want a IRC system, where you can type, and send messages, but the computer will, in the meantime check if theres a new message, and print it.
EDIT: I just read remiX's program critically, aaand… Im still not sure if that if that does what I want, I'm gonna test!
818 posts
Posted 16 December 2012 - 03:09 AM
You have 2 options here:
The not so flexible, but so much easiser parallel API
Or recoding a custom read that will accept a rednet message in between.
7508 posts
Location
Australia
Posted 16 December 2012 - 03:11 AM
you could also have a variable that holds what the user has typed, and on key press event add the char pressed. then if the event is rednet add it to the messages table
818 posts
Posted 16 December 2012 - 03:34 AM
that is the second option I wrote about.
7508 posts
Location
Australia
Posted 16 December 2012 - 03:37 AM
that is the second option I wrote about.
oh i thought you meant a custom read() lol
818 posts
Posted 16 December 2012 - 05:11 AM
yeah and that is exactly the meaning of what you wrote about… Anyways, back to topic!