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

[Lua][Error] Help with rednet?

Started by iMineing, 22 October 2012 - 06:00 AM
iMineing #1
Posted 22 October 2012 - 08:00 AM
Alright, so me and my friend have a factory, and he asked me to set up a gate that he can control by wireless from his office in said factory. But while coding his office computer I couldn't get the darn thing to send the message. All I get is

rednet:350: string expected

I know what it means, I just don't know why. I am trying to send a variable over to the computer that handles opening the gate, but it keeps returning that message. I defined the variable so I dunno.

Heres my code:


X = 1
if Command == "Open" then
term.clear()
write("Opening Gate")
rednet.open("left")
rednet.broadcast(X)
sleep(.3)
write(".")
sleep(.3)
write(".")
sleep(.3)
print(".")
sleep(1)
Menu()
end

Any help?

EDIT: There is code before this, thats why it is 350 and why I have "Command" in there
chiloxsan #2
Posted 22 October 2012 - 08:07 AM
You can only transmit strings with rednet. Use tostring(var) to convert your variable to a string, and use tonumber(string) the same way on the receiving side.

X = 1
if Command == "Open" then
term.clear()
write("Opening Gate")
rednet.open("left")
rednet.broadcast(tostring(X))
sleep(.3)
write(".")
sleep(.3)
write(".")
sleep(.3)
print(".")
sleep(1)
Menu()
end
remiX #3
Posted 22 October 2012 - 09:04 AM
Or just change x = 1 to x = "1"
sjele #4
Posted 22 October 2012 - 02:13 PM
It is better to do it Cholis way. If you did X = "1" every time you tried to compare it as a number, you would have to convert it to a number.