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

Help with a random error...

Started by SethShadowrider, 09 June 2012 - 11:34 PM
SethShadowrider #1
Posted 10 June 2012 - 01:34 AM
I am trying to create a turtle that can receive commands from afar wirelessly, but when I run the receive script I get this:

bios:206: [string "receive"]:3:
'then' expected


My code:

rednet.open("right")
id, msg = rednet.receive()
if msg = "cloak" then
print(Received)
shell.run("cloak")
rednet.close("right")
os.reboot()
end
MysticT #2
Posted 10 June 2012 - 01:38 AM
You need to use two = to compare:

if msg = "cloak" then
should be:


if msg == "cloak" then

Also, if you are trying to re-run your program, you should use a loop instead of rebooting the computer:

rednet.open("right")
while true do
  local id, msg = rednet.receive()
  if msg == "cloak" then
    print("Received") -- you forgot the quotes (") here
    shell.run("cloak")
    rednet.close("right")
  end
end
SethShadowrider #3
Posted 10 June 2012 - 01:41 AM
Oh! I get it now thanks!