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

Problem with rednet code for server

Started by Alex_, 17 March 2012 - 09:58 AM
Alex_ #1
Posted 17 March 2012 - 10:58 AM
This is my code so far for my beta
print("Starting CraftOs Server Program By Alex_")
rednet.open("right")
while true do
from,message = rednet.recieve
if message=="admin" then
print("username admin Logged")
rednet.broadcast("accept")
elseif message=="guest" then
print("Guest Logged")
rednet.broadcast("accept")
else
rednet.broadcast("er1")
end
end

after some loops i get the error
rednet:369: Too long without yielding

Can someone help me fix this because i don't understand this.
Casper7526 #2
Posted 17 March 2012 - 11:08 AM
If you dont yield a program every 10 seconds it will throw that error, your could simply do sleep(.1) and it would prevent the error (inside the loop of course)
Sebra #3
Posted 17 March 2012 - 04:34 PM
No, no. He tryes to get rednet message:
from,message = rednet.recieve
but it should have timeout like
from,message = rednet.recieve(1)
this chould solve problem without sleep
PatriotBob #4
Posted 19 March 2012 - 06:11 PM
Wouldn't he be better served to use…

while true do
    local event, sender, message = os.pullEvent()
    if event == "rednet_message" then
        --Do what ever you needed...
    end
    --Probably want a break condition to... but hey... :|
end

This way his program is waiting on an event rather than just thread spinning.
Wolvan #5
Posted 19 March 2012 - 06:23 PM

print("Starting CraftOs Server Program By Alex_")
rednet.open("right")
while true do
sleep(0)
from,message = rednet.recieve
if message=="admin" then
print("username admin Logged")
rednet.broadcast("accept")
elseif message=="guest" then
print("Guest Logged")
rednet.broadcast("accept")
else
rednet.broadcast("er1")
end
end
That worked for me. Just added the sleep(0)
Espen #6
Posted 19 March 2012 - 08:24 PM

print("Starting CraftOs Server Program By Alex_")
rednet.open("right")
while true do
sleep(0)
from,message = rednet.recieve
if message=="admin" then
print("username admin Logged")
rednet.broadcast("accept")
elseif message=="guest" then
print("Guest Logged")
rednet.broadcast("accept")
else
rednet.broadcast("er1")
end
end
That worked for me. Just added the sleep(0)
I highly doubt that it has worked for you with the code you posted here, because there is no rednet.recieve and there are no brackets at the end of the function call. :D/>/>
Wolvan #7
Posted 19 March 2012 - 11:04 PM

print("Starting CraftOs Server Program By Alex_")
rednet.open("right")
while true do
sleep(0)
from,message = rednet.recieve
if message=="admin" then
print("username admin Logged")
rednet.broadcast("accept")
elseif message=="guest" then
print("Guest Logged")
rednet.broadcast("accept")
else
rednet.broadcast("er1")
end
end
That worked for me. Just added the sleep(0)
I highly doubt that it has worked for you with the code you posted here, because there is no rednet.recieve and there are no brackets at the end of the function call. :D/>/>
Lol yeah I wrote it by hand in my PC and copied it here in the thread :)/>/>