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

rednet send problem

Started by GeniusName3, 29 December 2012 - 04:20 PM
GeniusName3 #1
Posted 29 December 2012 - 05:20 PM
Im making a simple msg system w/ CC

print(" what is the id of the computer you wish to send this message to")
local ID = read()
rednet.send("..id..", "from "..usr.." "..text"")

I only entered the part with errors the error says that the id part had to be a posotive number but i have the ..id part as a variable not an actual number
GopherAtl #2
Posted 29 December 2012 - 05:48 PM
you seem confused about the .. operator, which sticks variables together into stringsd. That code passes as the first param the string "..id..". It should just be id, ex

rednet.send(id,"from "..usr.." "..text)

you also need to convert id from a string, which read() returns, to a number, using tonumber(), ex:


write("target id >")
local id=read()
rednet.send( tonumber( id ) , "from "..usr.." "..text)
remiX #3
Posted 29 December 2012 - 10:41 PM
You have the right idea, atleast, but as GopherAtl said, you seem confused about the .. operator.
If you're just sending a simple string without concatenating anything to it, just have the string, or just the variable.
If you want concatenate something then you use .. but it must be outside the " "

print(" what is the id of the computer you wish to send this message to")
local ID = tonumber(read()) -- rednet.send requires a number to send the message to
-- Just to make it easier for now, concatenate the message you want to send in a variable
msg = "From " .. usr .. ": " .. text)
rednet.send(ID, msg)
--you wanted to send to 'id' but you use ID for read(), it's case sensitive :)/>