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

Rednet:39 Number Expected

Started by iLikePHP, 23 February 2014 - 09:23 AM
iLikePHP #1
Posted 23 February 2014 - 10:23 AM
Hello. I am working on a rednet relaying server for my new minecraft house and I am getting an error.

Here's my code, more explained later in the post:

local req_id, req_message = rednet.receive(5);
  if (req_message ~= nil) then
    where,cmd = req_message:match("([^,]+),([^,]+)");
    rednet.send(where, cmd, true);

A rednet message is sent into the server with something like this:
"10,command"
ID,CMD

I get the error:
rednet:39: Expected number

But there's a print straight after it, and when I comment out the send function, the print says:

print("Sent " .. cmd .. " to " .. where);
100% correctly, with the ID as it should be, and the command.
CometWolf #2
Posted 23 February 2014 - 03:48 PM
The definition for rednet.send is as follows

rednet.send(number receiverID, string message)
So that true at the end wouldn't do anything. Anyways, im guessing the problem is your where variable is a string. Give this a try

local req_id, req_message = rednet.receive(5);
  if (req_message ~= nil) then
	where,cmd = req_message:match("([^,]+),([^,]+)");
	rednet.send(tonumber(where), cmd);
Edited on 23 February 2014 - 02:48 PM
iLikePHP #3
Posted 23 February 2014 - 04:36 PM
The definition for rednet.send is as follows

rednet.send(number receiverID, string message)
So that true at the end wouldn't do anything. Anyways, im guessing the problem is your where variable is a string. Give this a try

local req_id, req_message = rednet.receive(5);
  if (req_message ~= nil) then
	where,cmd = req_message:match("([^,]+),([^,]+)");
	rednet.send(tonumber(where), cmd);

Thanks bud, worked great!