term.setCursorPos(0,3)
print("Computer id:")
term.setCursorPos(13,3)
id = io.read()
term.setCursorPos(13,3)
print(id)
term.setCursorPos(2,6)
print("Shutting Down Computer")
term.setCursorPos(2,7)
textutils.slowPrint("Please Wait.....................................")
rednet.send(id,".")
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
rednet:346: positive number expected
Started by brickw1994, 12 June 2012 - 10:26 PMPosted 13 June 2012 - 12:26 AM
Basically, i want to ask the user what id to send to, with a preset message, and send it without making alot of programs for each computer id. heres what i have.
Posted 13 June 2012 - 12:58 AM
read() returns a string, so change the last line to this:
rednet.send(tonumber(jd), ".")
So it becomes a numberPosted 13 June 2012 - 12:59 AM
thank you, ill try that :(/>/>
Posted 13 June 2012 - 01:04 AM
gives me shutdown:11: attempt to call string.
Posted 13 June 2012 - 01:28 AM
Oops, i made a typo.
Instead of "jd" try "id"
Instead of "jd" try "id"
Posted 13 June 2012 - 01:35 AM
okay now that works
1 more question, i wan tit to receive a message on seuccesful sending with the receiver sending me a message back but it crashes :(/>/>
1 more question, i wan tit to receive a message on seuccesful sending with the receiver sending me a message back but it crashes :(/>/>
id, message = rednet.receive()
term.setCursorPos(0,3)
print("Computer id:")
term.setCursorPos(13,3)
sid = io.read()
term.setCursorPos(13,3)
print(sid)
term.setCursorPos(2,6)
print("Shutting Down Computer")
term.setCursorPos(2,7)
textutils.slowPrint("Please Wait.....................................")
rednet.send(tonumber(sid),".")
if message == ".s" then --(the receive sends the message ".s: back to the sender)--
term.clear()
print("Done")
sleep(2)
shell.exit()
else
term.clear()
print("Shutdown failed")
sleep(2)
term.clear()
shell.exit()
end
Posted 13 June 2012 - 01:37 AM
What is the error?
Also, you stored io.read() AND the sender's ID both as "id", so you need to rename one.
Also, you stored io.read() AND the sender's ID both as "id", so you need to rename one.
Posted 13 June 2012 - 01:43 AM
theres not error it just locks up te computer, like its a loop or somethin
and i did change it look at the code
and i did change it look at the code
Posted 13 June 2012 - 01:47 AM
This should work:
rednet.open("<side>") -- change <side> to the side of the modem
term.setCursorPos(1, 3)
write("Computer id:")
local id = tonumber(read())
term.setCursorPos(2,6)
print("Shutting Down Computer")
term.setCursorPos(2,7)
textutils.slowPrint("Please Wait.....................................")
rednet.send(id, ".")
local sender, msg = rednet.receive()
if msg == ".s" then
term.clear()
term.setCursorPos(1, 1)
print("Done")
sleep(2)
shell.exit()
else
term.clear()
term.setCursorPos(1, 1)
print("Shutdown failed")
sleep(2)
shell.exit()
end
Posted 13 June 2012 - 01:52 AM
thanks mystic ill take a swing at it.
Posted 13 June 2012 - 02:08 AM
it still locks up at the local rednet receiver() part
Posted 13 June 2012 - 02:27 AM
brickw1992, whenever you do rednet.receive(), it stops until you receive a message unless you add a timer.
So if you do this instead:
So if you do this instead:
local sender, message = rednet.receive(1)
it will lockup until 1 second has passed or until it has been a minutePosted 13 June 2012 - 02:51 AM
ill have to give up on it its not working at all it wont send nor receive
Posted 13 June 2012 - 03:10 AM
did you forget rednet.open(<side>) ? or is it giving you an error
Posted 13 June 2012 - 03:13 AM
no its dumb. it just locks up and automatically gives me the else message, and the receivers is setup correctly, it just wont send, and yes the modem is open
Posted 13 June 2012 - 04:11 AM
Post code for receiving computer. I'm 100% certain that your client either doesn't send a message back upon receiving a message, or if it does, it doesn't send back '.s' which would be why the code always goes to the else message.
Secondly, you can use the parallel API to make this code more how I think you want it to be.
Secondly, you can use the parallel API to make this code more how I think you want it to be.
function printing()
term.setCursorPos(2,6)
print("Shutting Down Computer")
term.setCursorPos(2,7)
textutils.slowPrint("Please Wait.....................................")
rednet.send(id, ".")
end
function receive()
local sender, msg = rednet.receive()
end
parallel.waitForAny(printing, receive)
Posted 13 June 2012 - 04:49 AM
okay ill try that
Posted 13 June 2012 - 04:59 AM
heres the receiver, basicaly i want the receiver to shut off power to a place when a message saying ".sh"(was ".")then to make sure it sent send a message back.
receiver:
receiver:
rednet.open("right")
local id, message = rednet.receive()
if message == ".sh" then
print("did it")
rs.setOutput("top",true)
sleep(1)
end
Posted 13 June 2012 - 05:09 AM
Okay for this, I'd use a broadcast command instead of a send just to make sure it goes to the right computer. For the original program:
rednet.broadcast(".s")
Now when you call rednet.receive(), the client will send '.s' and the host will read it and continue with it's code correctly. If you change the confirmation message in the host or client, make sure you change it in the other program as well or else it won't work.Posted 13 June 2012 - 05:36 AM
it still doesnt want to work i tried the broadcast method, sril nothing, its like its not decoding the message. when i put rednet.receive() then print complete on the receiver it acted like it was getting the signal, idk justn wish there was a solution :(/>/>
Posted 13 June 2012 - 06:25 AM
i got it to work just had to take out some sleeps :(/>/>
thx for all your help guys
thx for all your help guys