Jump to content




rednet:87: Expected number

networking computer wireless

14 replies to this topic

#1 eniallator

  • Members
  • 56 posts

Posted 29 January 2016 - 11:24 AM

I've been working on a remote and a control program for a while now and i've recently ran into this error. the pastebin for the control program is here and the remote's pastebin is here.

To recreate the error with the programs, firstly have 2 seperate computers running each of the programs, next in the remote computer run "ls" and it should list available control computers to connect with. Once you have done this run "connect *id of the control computer that you want to connect with*" (the id is displayed in the list command). Then run "help" in the remote command line and it should display "no message received" (i have found that it sometimes errors and sometimes works and am not sure why).

Other information: I was running the control program with my farmTurtle plugin aswell as my minerTurtle plugin - i have tried printing out the help string with both plugins running in the control program and it has everything so i don't think it is the problem (although i could be wrong). I also tried using the other commands that the control program has and everything else works, its just the help command that seems to be erroring.

Edited by eniallator, 29 January 2016 - 11:38 AM.


#2 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 29 January 2016 - 11:30 AM

For some reason, without looking at the code, I'm thinking that the script is trying to use the distance value which rednet had but replaced with the protocol system.

Will investigate properly.

Edit:

Other way round, script is using protocols and rednet can't do that?

What version of CC are you using?

Edited by Lupus590, 29 January 2016 - 11:33 AM.


#3 eniallator

  • Members
  • 56 posts

Posted 29 January 2016 - 11:34 AM

View PostLupus590, on 29 January 2016 - 11:30 AM, said:

For some reason, without looking at the code, I'm thinking that the script is trying to use the distance value which rednet had but replaced with the protocol system.

Will investigate properly.

Edit:

Other way round, script is using protocols and rednet can't do that?

What version of CC are you using?

I was using 1.74 when i got that error

#4 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 29 January 2016 - 11:35 AM

Then it's neither of my suggestions.

I can decompose the error message for you.
rednet:87: Expected number
rednet is the name of the file which errored, this usually tells you the program but in this case it's the rednet API.
87 is the line number of the error.
Expected number is a description of the error, whatever was above line 87 did some data type checking and found that what should have been a number was some other type (such as a string or table)
if it needs saying, the colons : are just separators

Edited by Lupus590, 29 January 2016 - 11:41 AM.


#5 eniallator

  • Members
  • 56 posts

Posted 30 January 2016 - 02:42 PM

View PostLupus590, on 29 January 2016 - 11:35 AM, said:

Then it's neither of my suggestions.

I can decompose the error message for you.
rednet:87: Expected number
rednet is the name of the file which errored, this usually tells you the program but in this case it's the rednet API.
87 is the line number of the error.
Expected number is a description of the error, whatever was above line 87 did some data type checking and found that what should have been a number was some other type (such as a string or table)
if it needs saying, the colons : are just separators

was just playing around with it some more and it seems like when i try to load plugins that also have helps it errors when i try running the help command. I also know how error messages work & what they mean :P

#6 eniallator

  • Members
  • 56 posts

Posted 30 January 2016 - 02:54 PM

View Posteniallator, on 30 January 2016 - 02:42 PM, said:

View PostLupus590, on 29 January 2016 - 11:35 AM, said:

Then it's neither of my suggestions.

I can decompose the error message for you.
rednet:87: Expected number
rednet is the name of the file which errored, this usually tells you the program but in this case it's the rednet API.
87 is the line number of the error.
Expected number is a description of the error, whatever was above line 87 did some data type checking and found that what should have been a number was some other type (such as a string or table)
if it needs saying, the colons : are just separators

was just playing around with it some more and it seems like when i try to load plugins that also have helps it errors when i try running the help command. I also know how error messages work & what they mean :P

after further testing i've found what i think is the problem, when i try printing the help in the help function (ln 61) it doesn't print out anything - not even a blank space so what i have done is where i have a test for if msg[1] == "exit" (ln 207) i have an elseif testing if msg[1] == "help"

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 30 January 2016 - 03:28 PM

Which leads to a line with a missing bracket, apparently?

I took a look at the paste as it was a night or so ago, and didn't see anything which'd lead to the error. That and your latest upload make me wonder if I've actually seen a copy of the script which would've produced your original error.

Given your symptoms, I'm strongly suspecting that you've somehow messed up in terms of variable scope, or fed an incorrectly named variable into your original help function at some stage.

In any case, this guide would be well worth a read.

#8 eniallator

  • Members
  • 56 posts

Posted 30 January 2016 - 05:10 PM

View PostBomb Bloke, on 30 January 2016 - 03:28 PM, said:

Which leads to a line with a missing bracket, apparently?

I took a look at the paste as it was a night or so ago, and didn't see anything which'd lead to the error. That and your latest upload make me wonder if I've actually seen a copy of the script which would've produced your original error.

Given your symptoms, I'm strongly suspecting that you've somehow messed up in terms of variable scope, or fed an incorrectly named variable into your original help function at some stage.

In any case, this guide would be well worth a read.

been trying to use other functions and the same error message has been happening, i've also taken a read of the link and i knew it all already. but when i was just testing then i tried using upload then download then fileList and then move (from my minerTurtle plugin) and it errored at the move, but when i restarted and tried running fileList straight away, it errored.

Edited by eniallator, 30 January 2016 - 05:12 PM.


#9 valithor

  • Members
  • 1,053 posts

Posted 31 January 2016 - 01:10 AM

View Posteniallator, on 30 January 2016 - 05:10 PM, said:

View PostBomb Bloke, on 30 January 2016 - 03:28 PM, said:

-snip

been trying to use other functions and the same error message has been happening, i've also taken a read of the link and i knew it all already. but when i was just testing then i tried using upload then download then fileList and then move (from my minerTurtle plugin) and it errored at the move, but when i restarted and tried running fileList straight away, it errored.

Little debugging trick you can use to find it. Unload the rednet api (set _G.rednet to nil). Copy rednet from the rom to anywhere not the rom, and make sure the name is still rednet. Go into the copied file, and anywhere in the beginning of the function that line 87 is in do error checking to see if the first argument is a number. If it is not then make the function error with some easily identifiable message, and with a level 3 (might be 4) return (don't really know what to call this). This will make it error on the line that the function is called, instead of inside the rednet function. Then just use os.loadAPI to load the rednet api and run your program. If it errors encounters the same problem it will error and tell you exactly which of your rednet.sends is causing the bug.

I would try and find the bug, but I am unable to reproduce the error. So you can try and do this and provide us with the information.

Little snippet of what you would insert into the rednet function:
if type(whatEverTheFirstVariableInTheFunctionIsCalled) ~= "number" then
  error("This is the bad function call, number expected got" .. type(whatEverTheFirstVariableInTheFunctionIsCalled) ,3)
end

Edited by valithor, 31 January 2016 - 01:16 AM.


#10 eniallator

  • Members
  • 56 posts

Posted 31 January 2016 - 10:14 AM

View Postvalithor, on 31 January 2016 - 01:10 AM, said:

View Posteniallator, on 30 January 2016 - 05:10 PM, said:

View PostBomb Bloke, on 30 January 2016 - 03:28 PM, said:

-snip

been trying to use other functions and the same error message has been happening, i've also taken a read of the link and i knew it all already. but when i was just testing then i tried using upload then download then fileList and then move (from my minerTurtle plugin) and it errored at the move, but when i restarted and tried running fileList straight away, it errored.

Little debugging trick you can use to find it. Unload the rednet api (set _G.rednet to nil). Copy rednet from the rom to anywhere not the rom, and make sure the name is still rednet. Go into the copied file, and anywhere in the beginning of the function that line 87 is in do error checking to see if the first argument is a number. If it is not then make the function error with some easily identifiable message, and with a level 3 (might be 4) return (don't really know what to call this). This will make it error on the line that the function is called, instead of inside the rednet function. Then just use os.loadAPI to load the rednet api and run your program. If it errors encounters the same problem it will error and tell you exactly which of your rednet.sends is causing the bug.

I would try and find the bug, but I am unable to reproduce the error. So you can try and do this and provide us with the information.

Little snippet of what you would insert into the rednet function:
if type(whatEverTheFirstVariableInTheFunctionIsCalled) ~= "number" then
  error("This is the bad function call, number expected got" .. type(whatEverTheFirstVariableInTheFunctionIsCalled) ,3)
end

ok, i've just done a print in the original rednet api on line 87 where i just print(sModem,nRecipient,nReplyChannel) (not tMessage because its a table) and the first few times it says: right 0 1 (right being the side that the modem is on, 0 being the id that im sending to and 1 being the id of the control computer) and then on the third one it says the nRecipient is nil which i don't know why it is happening because im pretty sure im always sending the rednet function the right id. It then errors on the next line with the rednet:88: Expected number (ln 88 because of the print that i have before it).

#11 eniallator

  • Members
  • 56 posts

Posted 31 January 2016 - 10:44 AM

View Posteniallator, on 31 January 2016 - 10:14 AM, said:

View Postvalithor, on 31 January 2016 - 01:10 AM, said:

View Posteniallator, on 30 January 2016 - 05:10 PM, said:

View PostBomb Bloke, on 30 January 2016 - 03:28 PM, said:

-snip

been trying to use other functions and the same error message has been happening, i've also taken a read of the link and i knew it all already. but when i was just testing then i tried using upload then download then fileList and then move (from my minerTurtle plugin) and it errored at the move, but when i restarted and tried running fileList straight away, it errored.

Little debugging trick you can use to find it. Unload the rednet api (set _G.rednet to nil). Copy rednet from the rom to anywhere not the rom, and make sure the name is still rednet. Go into the copied file, and anywhere in the beginning of the function that line 87 is in do error checking to see if the first argument is a number. If it is not then make the function error with some easily identifiable message, and with a level 3 (might be 4) return (don't really know what to call this). This will make it error on the line that the function is called, instead of inside the rednet function. Then just use os.loadAPI to load the rednet api and run your program. If it errors encounters the same problem it will error and tell you exactly which of your rednet.sends is causing the bug.

I would try and find the bug, but I am unable to reproduce the error. So you can try and do this and provide us with the information.

Little snippet of what you would insert into the rednet function:
if type(whatEverTheFirstVariableInTheFunctionIsCalled) ~= "number" then
  error("This is the bad function call, number expected got" .. type(whatEverTheFirstVariableInTheFunctionIsCalled) ,3)
end

ok, i've just done a print in the original rednet api on line 87 where i just print(sModem,nRecipient,nReplyChannel) (not tMessage because its a table) and the first few times it says: right 0 1 (right being the side that the modem is on, 0 being the id that im sending to and 1 being the id of the control computer) and then on the third one it says the nRecipient is nil which i don't know why it is happening because im pretty sure im always sending the rednet function the right id. It then errors on the next line with the rednet:88: Expected number (ln 88 because of the print that i have before it).

I've found it!!!!!!!!!!!

in my minerTurtle plugin, i have a help function aswell that i accidently left in there - all fixed now. But thank you guys for the help! :D

#12 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 January 2016 - 11:09 AM

Since you've got such a good understanding of scope, I'm sure you can see how to make your script work even with such plugins present. ;)

#13 eniallator

  • Members
  • 56 posts

Posted 31 January 2016 - 11:43 AM

View PostBomb Bloke, on 31 January 2016 - 11:09 AM, said:

Since you've got such a good understanding of scope, I'm sure you can see how to make your script work even with such plugins present. ;)

do you mean like checking if it will work or not? like going through the plugins to see if they would work?

#14 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 January 2016 - 11:51 AM

What I'm getting at is that your script makes use of global variables exclusively. Any other scripts that place data into the global scope are prone to interfere.

If you localise all variables to your script, then other scripts can't touch them - whether or not they correctly localise their own variables.

#15 eniallator

  • Members
  • 56 posts

Posted 31 January 2016 - 12:03 PM

View PostBomb Bloke, on 31 January 2016 - 11:51 AM, said:

What I'm getting at is that your script makes use of global variables exclusively. Any other scripts that place data into the global scope are prone to interfere.

If you localise all variables to your script, then other scripts can't touch them - whether or not they correctly localise their own variables.

i have it intended that plugin's functions take priority over the default functions if that is what you mean, if you mean to just add local to all the variables i could probably do that though :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users