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

Switching on Lights via Rednet

Started by Beatsleigher, 13 December 2013 - 09:38 AM
Beatsleigher #1
Posted 13 December 2013 - 10:38 AM
Heyo,

I finally got my login program finished (thanks to the person who gave me the code I needed to start off with :)/> ), and I got everything else set up, but I'm having some trouble turning on the lights in my cellar.

This is the code the client receives:


-- Program can be terminated!
print("Opening rednet port...")
rednet.open("top")
print("Waiting for rednet signal....")
msg = rednet.receive()
print("Signal received.")
print("Processing signal. Please wait...")
if msg == "TurnOn" then
    print("Turning lights on!")
    -- Possible todo; add cool blink effect
    redstone.setOutput("front", true)
    sleep(1)
    redstone.setOutput("front", false)
    sleep(0.8)
    redstone.setOutput("front", true)
    sleep(2)
    redstone.setOutput("front", false)
    sleep(1)
    redstone.setOutput("front", true)
end
-- The rest loops for a rednet signal in the same way as above, to detect when to turn the lights off.

And this is the code the server sends:


print("Please wait...")
rednet.open("left")
on = "TurnOn"
off = "TurnOff"
print("Sending request...")
rednet.send(25, on)
print("Lights are turning on. Enjoy.")

I double-checked that the client's ID is 25, before trying, so it has to be something else.

Any help is much appreciated.

(P.S. Sorry if the code looks ugly. I'm used to languages like Java and C# :rolleyes:/> )
MKlegoman357 #2
Posted 13 December 2013 - 10:59 AM
rednet.receive() returns id and then the message:


local id, message, distance = rednet.receive()

print("Sender ID: " .. id)
print("Message: " .. message)
print("Distance between this computer and sender computer is " .. distance .. " block(s).")
Beatsleigher #3
Posted 13 December 2013 - 11:10 AM
rednet.receive() returns id and then the message:


local id, message, distance = rednet.receive()

print("Sender ID: " .. id)
print("Message: " .. message)
print("Distance between this computer and sender computer is " .. distance .. " block(s).")
Ohhh. Now that you say that, it does make sense. Thanks! :)/>