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

rednet.send() Question

Started by WeaponYT, 30 June 2017 - 09:20 AM
WeaponYT #1
Posted 30 June 2017 - 11:20 AM

--Sender Program by Weapon
rednet.open("back")
while true do
local id, msg = rednet.receive()
if (id == 1) then
  local msgs = msg
--Says what message it is
elseif (id == 3) then
  local ids = tonumber(msg)
--Gives Info About the ID receiver
end
rednet.send(ids, msgs)
print("Sent 1 message to "..ids)
end
The problem is tonumber() Wich doesnt work in the way I wanted. Please note that I am on CC 1.5 (Tekkit)
[rednet : 39 : Expected Number]
Please help!
P.S Code for Client Is :

--Mail Client by Weapon
rednet.open("back")
print("Enter Message:")
local msg = io.read()
print("Enter ID:")
local id = tonumber(io.read())
textutils.slowPrint("Sending . . .")
if rednet.send(1, msg) and rednet.send(3, id) then
print("Message Sent!")
else
print("Can't send Message! Try again Later.")
end

Code For MSG Router is (ID 1) :

--MSGSender by Weapon
rednet.open("back")
local msg = false
while true do
local id , msg = rednet.receive()
if msg then
rednet.send(2, msg)
print("Routed 1 message from "..id)
end
end

Code for ID sender (ID 3) is :

-- IDSender by Weapon
rednet.open("back")
local msg = false
while true do
local id, msg = rednet.receive()
if msg then
  rednet.send(2, msg)
  print("Routed 1 message from "..id)
end
end
Thanks for help!
Bomb Bloke #2
Posted 30 June 2017 - 01:52 PM
This is a matter of scope: declaring your "msgs" / "ids" variables as local to the "if" blocks means they no longer exist by the time you get to your rednet.send() call. Have a read through this, paying special attention to the bit about upvalues.
WeaponYT #3
Posted 11 July 2017 - 10:06 PM
Thanks!