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

[error][rednet] rednet not accepting numbers

Started by luewind, 05 November 2012 - 11:28 AM
luewind #1
Posted 05 November 2012 - 12:28 PM
I am trying to write a code for a redpower frame elevator that knows what floor it is at and uses a computercraft computer to control what floor it goes to. Everything else is set up fine but when i send a floor number to the elevator server it send back an error "rednet:350: string expected".
How do i get rednet to realize i am receiving a number and not a string?

Here is part of the code below that i am using, does everything look alright, and/ or should i post the rest of the code?

send code

  posChange = 54
  rednet.send(server, posChange, true)

receive code

  senders, posChange, distance = rednet.receive()
Pharap #2
Posted 05 November 2012 - 12:43 PM
Rednet only sends strings, so you have to do this:


send code

posChange = 54
  rednet.send(server, tostring(posChange), true)

receive code

  senders, posChange, distance = rednet.receive()
  posChange=tonumber(posChange)
luewind #3
Posted 05 November 2012 - 01:43 PM
thank you that solved my issue.
Pharap #4
Posted 05 November 2012 - 02:59 PM
You're welcome, tostring() and tonumber() come in very handy.

tostring will turn all numbers into strings, and tonumber will turn any valid strings into numbers
(if the string contains letters, it won't ignore them, it will just give back nil instead of a number)