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

Rednet Help Plz

Started by xtbs, 27 February 2012 - 04:08 AM
xtbs #1
Posted 27 February 2012 - 05:08 AM
So im messing around with rednet, and im trying to build a client server sort of system where I have a mainframe that has passcodes with clearance levels assigned to each one (one pass has a level three clearance another would have a level 1) (i know that this isnt very creative but im still trying to learn the api…) anyways, the client runs a program that will transmit a password to the server, the server then checks the password and sends the clearance number to the client, if the level isnt high enough there is no entry if it is then you can go in…

so as a test i mad a small program on the server that receives the code and if the code is right, it will send "true" to the client,
heres the code…

pass = rednet.receive(timeout)
if pass == 12345 then
rednet.broadcast(1)
end

Im pretty sure that the clients code is the problem though, the server is set to run the program once then it goes back to normal same with the client, but the client doesnt go back to normal… It stays as if its still waiting to receive…. the code for that is,

write "Enter Clearance Code…"

input = read()
rednet.broadcast(input)

code= rednet.receive(timeout)
if code == "true" then
print("TRUE")
end

if someone could tell me what im doing wrong and possible tell me what would work better i would appreciate it…

thanks in advance
Hawk777 #2
Posted 27 February 2012 - 05:54 AM
For one thing, you're sending the string "12345" over the network but, after receiving it, comparing it to the integer 12345. Change this:

if pass == 12345 then

to this:

if pass == "12345" then

Not sure if there are any other issues, but that's certainly one of them.
Liraal #3
Posted 27 February 2012 - 05:55 AM
rednet.open(side) to open a port for renet
rowantwig #4
Posted 27 February 2012 - 10:38 AM
rednet.receive() returns not only the message you gave to rednet.send() (or rednet.broadcast()), but also the ID of the sender.

Example, on receiver (id 0):
rednet.open("top")
local sender, message = rednet.receive()
print(sender)
print(message)

On sender (id 1):
rednet.open("top")
rednet.send(0, "hello")
rowantwig #5
Posted 27 February 2012 - 10:55 AM
Sorry, posted in wrong thread (this post, not the previous one).