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

Number expected error

Started by kpfromer, 28 September 2013 - 05:18 PM
kpfromer #1
Posted 28 September 2013 - 07:18 PM
Help I made a program to allow people to talk via rednet and it says expected number Heres My Code: print("Chatter 1.0! By Kpfromer")
write("Id:")
local id = read()
write("Message:")
local message = read()
rednet.send(id, message)
Lyqyd #2
Posted 28 September 2013 - 09:33 PM
Split into new topic.

Go read the sticky posts.

read() returns strings. Use tonumber to convert id to a number.
kpfromer #3
Posted 28 September 2013 - 09:52 PM
How? Can I Have An Example!
Inumel #4
Posted 28 September 2013 - 10:35 PM
How? Can I Have An Example!


print("Chatter 1.0! By Kpfromer")
write("Id:")
local id = tonumber(read())
write("Message:")
local message = read()
rednet.send(id, message)
Engineer #5
Posted 29 September 2013 - 11:37 AM
How? Can I Have An Example!


print("Chatter 1.0! By Kpfromer")
write("Id:")
local id = tonumber(read())
write("\nMessage:")
local message = read()
rednet.send(id, message)

I would suggest that makes sure you have a number:

print("Chatter 1.0! By Kpfromer")
write("Id:")
local id
repeat
   id = tonumber( read() ) -- if the read is not a number, then id will be nil.
until id 
write("Message:")
local message = read()
rednet.send(id, message)