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

rednet:346: positive number expected

Started by brickw1994, 12 June 2012 - 10:26 PM
brickw1994 #1
Posted 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.





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,".")
ComputerCraftFan11 #2
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 number
brickw1994 #3
Posted 13 June 2012 - 12:59 AM
thank you, ill try that :(/>/>
brickw1994 #4
Posted 13 June 2012 - 01:04 AM
gives me shutdown:11: attempt to call string.
ComputerCraftFan11 #5
Posted 13 June 2012 - 01:28 AM
Oops, i made a typo.

Instead of "jd" try "id"
brickw1994 #6
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 :(/>/>


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


ComputerCraftFan11 #7
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.
brickw1994 #8
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
MysticT #9
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
brickw1994 #10
Posted 13 June 2012 - 01:52 AM
thanks mystic ill take a swing at it.
brickw1994 #11
Posted 13 June 2012 - 02:08 AM
it still locks up at the local rednet receiver() part
ComputerCraftFan11 #12
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:

local sender, message = rednet.receive(1)
it will lockup until 1 second has passed or until it has been a minute
brickw1994 #13
Posted 13 June 2012 - 02:51 AM
ill have to give up on it its not working at all it wont send nor receive
PixelToast #14
Posted 13 June 2012 - 03:10 AM
did you forget rednet.open(<side>) ? or is it giving you an error
brickw1994 #15
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
Bossman201 #16
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.

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)
brickw1994 #17
Posted 13 June 2012 - 04:49 AM
okay ill try that
brickw1994 #18
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:

rednet.open("right")
local id, message = rednet.receive()
if message == ".sh" then
print("did it")
rs.setOutput("top",true)
sleep(1)
end
Bossman201 #19
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.
brickw1994 #20
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 :(/>/>
brickw1994 #21
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