Jump to content




Rednet Problem - rednet:87: Expected number


  • You cannot reply to this topic
2 replies to this topic

#1 Zukamimozu

  • Members
  • 26 posts

Posted 11 October 2014 - 10: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.

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 11 October 2014 - 10: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 by MKlegoman357, 11 October 2014 - 10:22 PM.


#3 Zukamimozu

  • Members
  • 26 posts

Posted 11 October 2014 - 11:13 PM

Thank you so much! Didn't know about the string thing, it works now.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users