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

Rednet Problem - rednet:87: Expected number

Started by Zukamimozu, 11 October 2014 - 09:15 PM
Zukamimozu #1
Posted 11 October 2014 - 11:15 PM
So I'm pretty new to Computer Craft and I'm trying to set up a system to open and close doors with the wireless pocket computer. I have a computer that receives the signal and will open/close the doors. On the pocket Computer I have

term.clear()
term.setCursorPos(1,1)
print("Receiver ID: ")
local receiver = read()
term.clear()
term.setCursorPos(1,1)
print("Message: ")
local message = read()
rednet.send(receiver,message)
term.clear()
term.setCursorPos(1,1)
print("Message Sent")
sleep(1.5)
term.clear()
term.setCursorPos(1,1)
So it works fine until I get to the point where I send the message part of the code. Once I hit enter on the message part it says rednet:87: Expected number

I don't know how to fix this. Any help would be nice! Thanks.
MKlegoman357 #2
Posted 11 October 2014 - 11:21 PM
read() function returns a string. You use this function to get the receiver's ID from the user. rednet.send() requires a number as the first argument, but you're giving it a string. To convert a string to a number you can use the tonumber() function:


local stringX = "20"

local number = tonumber( stringX )
Edited on 11 October 2014 - 09:22 PM
Zukamimozu #3
Posted 12 October 2014 - 12:13 AM
Thank you so much! Didn't know about the string thing, it works now.