1

This is my first time using Lua, and with following a tutorial, Im making a chat program, allowing two players to send and receive messages to each other. The receiving is called chatreceive.lua. The script is:

rednet.open("right")
sender, message = rednet.receive()
print("computer " .. sender .. " has sent :")
print(message)

I keep getting an error saying

chatreceive.lua:3: attempt to concatenate global 'sender' (a nil value)

Any solutions? Ive been trying for a while now

csaar
  • 530
  • 5
  • 22
Ben G
  • 21
  • 1
  • You should ensure `sender` is not nil, you can't concatenate a nil value. For instance `if (sender and message) then`. – csaar Jul 16 '21 at 12:21

1 Answers1

0

That means that the variable 'sender' was nil. This probably means that there was some sort of error with rednet. You should add a lot of checks to make sure your programs don't fail in critical situations:

if sender==nil then
  print("SENDER IS NIL!!!")
end

Also, what version of CC are you using? You shoud be more specific, to get better answers...

Promitheas Nikou
  • 511
  • 4
  • 14