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

Having trouble Receiving/Printing Messages

Started by Wing, 24 August 2012 - 10:43 PM
Wing #1
Posted 25 August 2012 - 12:43 AM
Hey everyone again!
Here I find myself left wondering what is wrong…. My problem you must ask? Well see, for some reason my first function just doesn't seem to work! It might be a problem of timing,although I don't think so. But anyway here is my code (feel free to optimize)

function received()
rednet.open("right")
X = 0
Y = 1
e, id, msg = os.pullevent
if e == "rednet_message" then
    Y = Y +1
    sleep(1)
    if Y > 18 then
	    term.scroll()
	    term.setCursorPos(X, Y)
	    print(id, msg)
	    received()
    else
	    term.setCursorPos(X, Y)
	    print(id, msg)
	    received()
	    end
else
sending()
end
end

function sending()
local name = os.computerID()
while true do
local sEvent, param = os.pullEvent("key")
if (sEvent == "key") then
    if (param == 28) then
	    sending = read()
	    Y = Y +1
	    if Y > 18 then
		    term.scroll(1)
		    rednet.close("right")
		    rednet.open("left")
		    rednet.broadcast(sending)
		    sleep(1)
		    rednet.close("left")
		    rednet.open("right")
	    else
		    rednet.close("right")
		    rednet.open("left")
		    rednet.broadcast(sending)
		    sleep(1)
		    rednet.close("left")
		    rednet.open("right")
		    end
	    end
    end
end
sleep(1)
received()
end
received()

Thanks for any help in advance!
Lyqyd #2
Posted 25 August 2012 - 12:59 AM
Well, for one thing, that's going to overflow the stack if you leave it running for any length of time. You'll need to use an infinite loop rather than recursion to keep repeating the code.
immibis #3
Posted 25 August 2012 - 07:21 AM
Also os.pullEvent has a capital E, and you're missing brackets after it
Wing #4
Posted 26 August 2012 - 02:09 AM
I tried that Immibis but it still doesn't work….
Wing #5
Posted 28 August 2012 - 02:28 AM
Can anyone help?