hanableking82 Posted October 22, 2012 Posted October 22, 2012 I am not pro or even close, maybe someone could tell me whats wrong with this code? or maybe even write it correctly and show me the difference.Trying to send a signal from one computer to another using rednet to turn on redstone machines. Searched the internet for hours looking for an answer but nothing. rednet.open ("top") local event,p1,p2,p3 = os.pullEvent() if event=="rednet_message" and p1==16 then rednet.send(p1,p2,p3"ack") if p2 == "m1 on" then redset left false elseif p2 == "m1 off" then redset left true elseif p2 == "m2 on" then redset left false elseif p2 == "m2 off" then redset left true end end end this code would be on the receiving end of the command hooked to the redstone/wire Quote
Linear_Spoon Posted October 22, 2012 Posted October 22, 2012 not sure what you've got going on here but here is are basic server/client scripts the client code: rednet.open("top") print("Looking for a server...") while ID == nil do rednet.announce() --sends an empty rednet message so server can get its ID ID, message, distance = rednet.receive(5) --5 is the timeout in seconds end print("Server replied!") print("ID: "..ID) print("Message: "..message) print("distance: "..distance) rednet.send(ID, "Found you!") --To send a message back to the server rs.setOutput("back", true) --Or to change the redstone state of a side the server code: rednet.open("top") -- parameter is the side with the modem while true do print("Waiting for a client...") ID, message, distance = rednet.receive() --no parameter means wait forever if ID ~= nil then --nil ID might be returned if you have a timeout on rednet.receive() print("Found a client!") print("ID: "..ID) print("Message: "..message) print("distance: "..distance) rednet.send(ID, "Hello") --To send a message back to the client end end I hope this helps Quote
hanableking82 Posted October 22, 2012 Author Posted October 22, 2012 thanks, still a little confused. I wanna send from my main compter down to where the "client" computer is say like "m1 on" it will turn on machine 1 and "m1 off" it will turn it off. I have 7 machines so I could do the bundled cable but not sure if what you wrote would work for that? Quote
Linear_Spoon Posted October 22, 2012 Posted October 22, 2012 It was just a general example of syntax You can modify the server code to send the message "m1 on" and put something like this on the client if message == "m1 on" then -- turn the first machine on else if message == "m1 off" then -- turn the first machine off end Bundled cable is more complicated than standard redstone signals but here's a basic example rs.setBundledOutput("left", colors.white+colors.blue+colors.green) --power the white, blue, and green wires of a bundled cable attached to the left side (this will turn off any other colors) if rs.getBundledOutput("left") == colors.white then print("The white cable is powered") end rs.setBundledOutput("left", 0) --turn all wires off My advice would be to put the client into a loop and wait for server messages indefinitely local activeColors = 0 --this will be a numeric representation of all the colors currently powered while true do ID, message, distance = rednet.receive() if message == "m1 on" then if colors.test(activeColors, colors.blue) == false then --if the blue cable is off, you need this check so activeColors doesn't get messed up by adding a color that's already on activeColors = activeColors + colors.blue --to remember blue as on for later rs.setBundledOutput("left", activeColors) -- to power it (this will keep all the other colors powered if you follow the same format for each machine) end end if message == "m1 off" then if colors.test(activeColors, colors.blue) then --if the blue cable is on activeColors = activeColors - colors.blue rs.setBundledOutput("left", activeColors) end end -- put similar if statements for all the other machines, just changing the colors.xxxx and "mx on/off" end Im writing this on my break between classes so if there's an error I'm sorry I couldn't get on minecraft to test it Quote
hanableking82 Posted October 22, 2012 Author Posted October 22, 2012 thanks friend I will try this out! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.